Dim plage As Range, c As Range
Dim Adr1 As String
Dim NomEnCours As String
Dim bChargementListe As Boolean
Private Sub btnSuivant_Click()
If btnSuivant.Caption = "Recommencer" Then
NomEnCours = ""
cbDenomination_Change
Exit Sub
End If
If Not c Is Nothing Then
Set c = plage.FindNext(c)
If Not c Is Nothing Then
If c.Address <> Adr1 Then
tbAdresse = c.Offset(, 1)
tbCP = c.Offset(, 2)
tbVille = c.Offset(, 3)
Else
btnSuivant.Caption = "Recommencer"
lblMsg = "Fin de la recherche"
End If
End If
End If
End Sub
Private Sub cbDenomination_Change()
' Si la procédure est appelée lors du chargement de la liste ou
' qu'aucun choix dans la combo on sort
If cbDenomination.ListIndex = -1 Or bChargementListe Then Exit Sub
'conserver la première adresse de cellule trouvée
Adr1 = "": lblMsg = ""
btnSuivant.Caption = "Suivant"
' Trouver la première occurence
If NomEnCours <> cbDenomination.Value Then
Set c = plage.Find(what:=cbDenomination.Value, LookIn:=xlValues)
If Not c Is Nothing Then
Adr1 = c.Address
NomEnCours = c.Value
btnSuivant.Enabled = True
tbAdresse = c.Offset(, 1)
tbCP = c.Offset(, 2)
tbVille = c.Offset(, 3)
Else
btnSuivant.Enabled = False
lblMsg = "Aucune occurence trouvée"
End If
End If
End Sub
Private Sub UserForm_Initialize()
Dim c As Range
Set plage = Feuil1.Range("A1:A" & Feuil1.Range("A65536").End(xlUp).Row)
'On ajoute des occurences uniques à la combobox des noms
bChargementListe = True
For Each c In plage.Cells
If c.Row <> plage.Range("A1").Row Then
cbDenomination.Text = Trim(c.Text) 'cette ligne entraine l'évènement cbNoms_Click()
If cbDenomination.ListIndex = -1 Then cbDenomination.AddItem c
End If
Next
cbDenomination.ListIndex = -1
bChargementListe = False
End Sub