simplification de code recherche
Bonsoir,
Je reviens vous voir en espérant de l'aide de votre part.
j'ai réussi à faire un code mais un peu galère, il fonctionne mais je pense pas que se soit le mieux.
j'ai un userform avec un combobox1 et 3 label, avec le combobox je sélectionne mon client qui lui est en feuil1(colonne q3:q25) et 2 cellule à gauche le n° de devis(colonne o3:o25) lui correspondant,
le truc c'est qui peux y avoir une ou plusieurs ligne correspondant à ce client.
donc ce que je souhaiterai c'est que qu'en je sélectionne le client via le combobox, le label1 me marque le devis lui étant attribué ou les devis après en label2 et 3.
en vous remerciant de l'aide que vous m'apporterez
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Private Sub ComboBox1_Change()
Dim nom As Range
Dim chaine As String, trouve As String
chaine = ComboBox1.Value
Set nom = Sheets("nico").Columns(1).Cells.Find(chaine, , xlValues, xlWhole)
trouve = nom.Address
If Not nom Is Nothing Then
nom.Select
Me.Controls("Label1").Caption = ActiveCell.Offset(0, 1)
Set nom = Sheets("nico").Columns(1).FindNext(nom)
End If
If Not nom Is Nothing Then
nom.Select
Me.Controls("Label2").Caption = ActiveCell.Offset(0, 1)
Set nom = Sheets("nico").Columns(1).FindNext(nom)
End If
If Not nom Is Nothing Then
nom.Select
Me.Controls("Label3").Caption = ActiveCell.Offset(0, 1)
Set nom = Sheets("nico").Columns(1).FindNext(nom)
End If
If Label1.Caption = Label2.Caption Then
Label2.Visible = False
End If
If Label2.Caption = Label3.Caption Then
Label3.Visible = False
End If
If Label1.Caption = Label3.Caption Then
Label3.Visible = False
End If
End Sub |