Bonjour,
Dans le cadre de mon travail, je fais actuellement un suivi de livraison de matériel.
Je dois pouvoir extraire dans une feuille excel des données issues d'une 2° feuille excel grâce à des valeurs choisies dans des combo box par l'utilisateur.
Actuellement, je peux avoir 3 choix en simultané.
Ce que je n'arrive pas à faire :
1 - rechercher mes valeurs dans la feuille excel (à une colonne précise) en comparant à ma donnée Combobox (ComboCommand, par exemple)
2 - Copier la ligne dans une nouvelle page.
Je tiens à préciser que mes Combo se chargent automatiquement en fonction des valeurs trouvées dans la feuille d'origine excel et que ceci fonctionne bien.
Voici le code tapé pour l'instant :
Private Sub Userform_initialize()
'Initialisation des variables
Dim I As Long
Dim LastLine As Long
Dim Command As String
Dim Client As String
Dim Livr As String
'Test fin de tableau
LastLine = Worksheets("Ep 40 mm").Cells(65535, 1).End(xlUp).Row
'MsgBox (LastLine)
'Initialisation des combo
'Commande
ComboCommand.AddItem ("")
For I = 2 To LastLine
Command = Worksheets("Ep 40 mm").Cells(I, 1).Value
ComboCommand.Text = Command
If ComboCommand.ListIndex = -1 Then
ComboCommand.AddItem (Command)
End If
Next I
ComboCommand.ListIndex = 0
'Client
ComboClient.AddItem ("")
For I = 2 To LastLine
Client = Worksheets("Ep 40 mm").Cells(I, 7).Value
ComboClient.Text = Client
If ComboClient.ListIndex = -1 Then
ComboClient.AddItem (Client)
End If
Next I
ComboClient.ListIndex = 0
'Livraison
ComboLivr.AddItem ("")
For I = 2 To LastLine
Livr = Worksheets("Ep 40 mm").Cells(I, 8).Value
ComboLivr.Text = Livr
If ComboLivr.ListIndex = -1 Then
ComboLivr.AddItem (Livr)
End If
Next I
ComboLivr.ListIndex = 0
End Sub
Private Sub BtFind_Click()
Dim LastLine As Long
Dim Col As Long
Dim Lig As Long
'Test fin de tableau
LastLine = Worksheets("Ep 40 mm").Cells(65535, 1).End(xlUp).Row
Sheets("recherche Ep 40 mm").Activate ' feuille de destination
With Sheets("Ep 40 mm") 'feuille origine
Col = 1
Lig = 2
For Lig = 2 To Lig = LastLine
If .Cells(Lig, Col).Value = ComboCommand.Value Then
.Cells(Lig, Col).EntireRow.Copy
Lig = Lig + 1
Sheets("recherche Ep 40 mm").Cells(Lig, 1).Insert Shift:=xlDown
End If
Next
End With
End Sub