VBA excel ComboBox

Résolu/Fermé
jh50160 Messages postés 90 Date d'inscription samedi 15 juillet 2006 Statut Membre Dernière intervention 12 janvier 2024 - 5 févr. 2009 à 07:11
 Utilisateur anonyme - 5 févr. 2009 à 14:41
salut à tous, petit problème avec mon comboBox. J'ai un userform1 avec textBox et ComboBox, dans le combobox 1 j'ai une liste avec les mois, je voudrais que quand je selection janvier les résultat des autre comboBox et textBox s'inscrivent dans la feuille Janvier, si selection février dans feuille février et ainsi de suite. j'ai se code là
Merci de bien vouloir m'aider. A+


'Met en place les données dans les cellules de la feuille de calcul'
Private Sub CommandButton1_Click() 'bouton enregistrer'
Dim i As Byte, Nom As String
Dim DerLig As Long
Nom = ComboBox1
With Sheets(Nom)
DerLig = .Range("A65536").End(xlUp).Row + 1
.Cells(DerLig, 1) = CombiBox2
.Cells(DerLig, 2) = ComboBox3
.Cells(DerLig, 3) = TextBox3
.Cells(DerLig, 4) = ComboBox5
.Cells(DerLig, 5) = ComboBox4
.Cells(DerLig, 6) = ComboBox6
.Cells(DerLig, 7) = TextBox1
.Cells(DerLig, 8) = TextBox2
End With
Unload Me
End Sub
A voir également:

4 réponses

wilfried_42 Messages postés 907 Date d'inscription mardi 19 août 2008 Statut Contributeur Dernière intervention 8 décembre 2009 242
5 févr. 2009 à 09:13
Bonjour

selon ce que j'en lis, le code affiché (mise à part des fautes de frappe : combibox) doit faire ce que tu demandes, à la seule condition que les noms de feuille soient exactement identiques aux valeurs contenues dans la combobox
1
jh50160 Messages postés 90 Date d'inscription samedi 15 juillet 2006 Statut Membre Dernière intervention 12 janvier 2024
5 févr. 2009 à 13:08
Bonjour WilFried, je n'arrive pas à trouver erreur peut tu m'aider, je te met mon fichier à l'adresse ci-dessous
et Merci.

http://www.cijoint.fr/cjlink.php?file=cj200902/cijqBsigOx.xls
0
wilfried_42 Messages postés 907 Date d'inscription mardi 19 août 2008 Statut Contributeur Dernière intervention 8 décembre 2009 242
5 févr. 2009 à 13:53
re:

dans ta combobox tu as JANVIER 2009 et tes feuilles sont nommées Janvier 2009 (majuscules, minuscules)
0
Utilisateur anonyme
5 févr. 2009 à 14:12
Bonjour,

un des problèmes est que les noms figurants dans la feuille "Listes" ne correspondent pas
aux noms des feuilles associées.

Dans la routine : [ Private Sub CommandButton1_Click() ]

J'ai du manipuler la valeur du ComboBox comme suit :
' Met en place les données dans les cellules de la feuille de calcul
Private Sub CommandButton1_Click()

    Dim i As Byte, Nom As String, DerLig As Long
    Dim Dum As String, Longueur As Integer
        
    Nom = ComboBox1.Value
    Dum = Right(Nom, 2)
    Longueur = Len(Nom)
    Nom = Mid(Nom, 1, (Longueur - 4))
    Nom = Nom & Dum
    Nom = LCase(Nom)
    Nom = Trim(Nom)
    Dum = UCase(Left(Nom, 1))
    Nom = Dum & Mid(Nom, 2)
    
    With Sheets(Nom)
        DerLig = .Range("A65536").End(xlUp).Row + 1
        .Cells(DerLig, 1) = ComboBox2
        .Cells(DerLig, 2) = ComboBox3
        .Cells(DerLig, 3) = TextBox3
        .Cells(DerLig, 4) = ComboBox5
        .Cells(DerLig, 5) = ComboBox4
        .Cells(DerLig, 6) = ComboBox6
        .Cells(DerLig, 7) = TextBox1
        .Cells(DerLig, 8) = TextBox2
    End With
    
    Unload Me
    
End Sub
'


autre recommandation, dans la routine : [ Private Sub ComboBox3_Change() ]

vous devriez écrire comme ceci :
' Faire apparaitre un textBox suivant la sélection dans la ComboBox
Private Sub ComboBox3_Change()

    Select Case ComboBox3.Value
        Case "CB"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "CB Internet"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "CB Retrait"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "Chèque"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'TextBox pour le créditCacher
            TextBox3.Visible = True 'TextBox pour rentrer le N° chèque affiche
        Case "Prélèvement "
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "Prélèvement CB"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "Retrait Chèque"
            TextBox1.Visible = True 'afficher
            TextBox2.Visible = False 'Cacher
            TextBox3.Visible = False 'Cacher
        Case "Virement"
            TextBox1.Visible = False 'cacher
            TextBox2.Visible = True   'Afficher
            TextBox3.Visible = False 'Cacher
        Case "Rem Chèque"
            TextBox1.Visible = False 'Cacher
            TextBox2.Visible = True   'Afficher
            TextBox3.Visible = False 'Cacher
        Case "Virement"
            TextBox1.Visible = False 'Cacher
            TextBox2.Visible = True   'Afficher
            TextBox3.Visible = False 'Cacher
        Case "Rem Liquide"
            TextBox1.Visible = False 'Cacher
            TextBox2.Visible = True   'Afficher
            TextBox3.Visible = False 'Cacher
        Case "Rem Niveau"
            TextBox1.Visible = False 'Cacher
            TextBox2.Visible = True   'Afficher
            TextBox3.Visible = False 'Cacher
    End Select
    
End Sub
'

Lupin
0
Utilisateur anonyme
5 févr. 2009 à 14:41
re:

Autre point :

Pour que l'instruction [ DerLig = .Range("A65536").End(xlUp).Row + 1 ] fonctionne bien

Placer en A4 de chaque page [ Janvier ... Décembre ] la valeur 0 et placer la couleur du texte
en Blanc.

Et voici ler code :
' Met en place les données dans les cellules de la feuille de calcul
Private Sub CommandButton1_Click()

    Dim i As Byte, Nom As String, DerLig As Long
    Dim Dum As String, Longueur As Integer
        
    Nom = ComboBox1.Value
    Dum = Right(Nom, 2)
    Longueur = Len(Nom)
    Nom = Mid(Nom, 1, (Longueur - 4))
    Nom = Nom & Dum
    Nom = LCase(Nom)
    Nom = Trim(Nom)
    Dum = UCase(Left(Nom, 1))
    Nom = Dum & Mid(Nom, 2)
    
    DerLig = Sheets(Nom).Range("A65536").End(xlUp).Row + 1
    With Sheets(Nom)
        .Cells(DerLig, 1) = ComboBox2
        .Cells(DerLig, 3) = ComboBox3
        .Cells(DerLig, 4) = TextBox3
        .Cells(DerLig, 5) = ComboBox5
        .Cells(DerLig, 6) = ComboBox4
        .Cells(DerLig, 7) = ComboBox6
        .Cells(DerLig, 8) = TextBox1
        .Cells(DerLig, 9) = TextBox2
    End With
    
    Unload Me
    
End Sub
'

Lupin
0