probleme VBA

madgicbobbyboon

XLDnaute Junior
Bonjour et d'avance merci pour les réponses que vous allez m'apporter.

J'ai un userform avec 2 combobox.
la combobox1 est alimenter en fonction de la combobox2.
La combobox1 = délégation départementale
la combobox2 = immatriculation de véhicule

Mon probleme est pour la validation (commandbutton1).

Je n'ai aucune idée du code a mettre.

merci
 

Pièces jointes

  • gestion automobile test.xlsm
    60.1 KB · Affichages: 39

Lone-wolf

XLDnaute Barbatruc
Bonjour madgicbobbyboon


Dans la macro d'appel du formulaire : UserForm1.Show 0

Dans la macro de combobox 2, ajoute ceci

Dim Sh As WorkSheet

For each sh in Worksheets
If sh.Name = ComboBox2.Text Then Sh.Activate
Next Sh

Avec le bouton de validation

With Activesheet
lig = .Cells(rows.count, 1).End(xlUp).Row + 1
.Cells(lig, 1) = xxxx
.Cells(lig, 2) = yyyy
.Cells(lig, 3) = zzzz
etc.
End With
 
Dernière édition:

madgicbobbyboon

XLDnaute Junior
Re pierrejean :)

Le monde est petit comme on dit n'est pas? ;)
Bonjour madgicbobbyboon


Dans la macro d'appel du formulaire : UserForm1.Show 0

Dans la macro de combobox 2, ajoute ceci

Dim Sh As WorkSheet

For each sh in Worksheets
If sh.Name = ComboBox2.Text Then Sh.Activate
Next Sh

Avec le bouton de validation

With Activesheet
lig = .Cells(rows.count, 1).End(xlUp).Row + 1
.Cells(lig, 1) = xxxx
.Cells(lig, 2) = yyyy
.Cells(lig, 3) = zzzz
etc.
End With
Merci beaucoup
je vais essayer et je reviens vers vous si ça coince :)
 

Lone-wolf

XLDnaute Barbatruc
Bonjour madgic

Au cas où tu repasse par ici
VB:
Private Sub ComboBox2_Change()
    If ComboBox2.Text <> "" Then
        Call Inscriptions
    Else
        Exit Sub
    End If
End Sub

Private Sub Inscriptions()
Dim Sh As Worksheet, i As Long

    If Me.ComboBox2.ListIndex = -1 Then Exit Sub
    With Me.ComboBox1
        .Clear
        For i = 2 To Ws.Cells(Me.ComboBox2.Column(1), Columns.Count).End(xlToLeft).Column
            .AddItem Ws.Cells(Me.ComboBox2.Column(1), i)
        Next i
    End With

    Label2.Visible = True
    ComboBox1.Visible = True
    For Each Sh In Worksheets
        If Sh.Name = ComboBox2.Text Then Sh.Activate
    Next Sh
End Sub

Private Sub CommandButton1_Click()
Dim derlig As Long, Reponse

    Reponse = MsgBox("Confirmez vous l'ajout de la fiche " & ComboBox1, vbYesNo, "Attention")

    If Reponse = vbYes Then
        With ActiveSheet
            derlig = .Range("a" & Rows.Count).End(xlUp).Row
            If derlig = 1 Then
                derlig = 3
            Else
                derlig = derlig + 1
            End If
            .Range("A" & derlig) = ComboBox1.Value
            .Range("L" & derlig) = TextBox2.Value
        End With
    Else
        Unload Me
    End If
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 730
Messages
2 081 989
Membres
101 856
dernier inscrit
Marina40