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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| Private Sub ListBoxLocataire_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ligSelect = ListBoxLocataire.Column(7, ListBoxLocataire.ListIndex)
usfAffichage.Show
End Sub
Private Sub RechercheC2_Change()
' Rechercher les données en fonction des critères sélectionnés
Call Rechercher
End Sub
Private Sub UserForm_Initialize()
Range("A2").Select
' Initialiser les listes des critères
Call InitCombo(RechercheC1, "A")
Call InitCombo(RechercheC2, "B")
' Rechercher les données en fonction des critères sélectionnés
Call Rechercher
End Sub
Private Sub RechercheC1_Change()
' Rechercher les données en fonction des critères sélectionnés
Call Rechercher
End Sub
Private Sub Rechercher()
' Rechercher les données en fonction des critères 1 et 2
Dim rCel As Range
Dim lgLig As Long
Dim lgLigDeb As Long
Dim Critere1 As String
Dim Critere2 As String
Critere1 = "*"
If RechercheC1.Value <> "" Then Critere1 = RechercheC1.Value
Critere2 = "*"
If RechercheC2.Value <> "" Then Critere2 = RechercheC2.Value
ListBoxLocataire.Clear
' Boucle de la 2me à la dernière ligne de la feuille Feuil1
For lgLigDeb = 2 To Range("A" & Cells.Rows.Count).End(xlUp).Row
If Range("A" & lgLigDeb).Value Like Critere1 And Range("B" & lgLigDeb).Value Like Critere2 Then
With ListBoxLocataire
.AddItem Range("A" & lgLigDeb).Value
.List(.ListCount - 1, 1) = Range("B" & lgLigDeb).Value
.List(.ListCount - 1, 2) = Range("C" & lgLigDeb).Value
.List(.ListCount - 1, 3) = Range("D" & lgLigDeb).Value
.List(.ListCount - 1, 4) = Range("E" & lgLigDeb).Value
.List(.ListCount - 1, 5) = Range("F" & lgLigDeb).Value
.List(.ListCount - 1, 6) = Range("G" & lgLigDeb).Value
.List(.ListCount - 1, 7) = lgLigDeb
lgLig = lgLig + 1
End With
End If
Next lgLigDeb
End Sub
Private Sub InitCombo(LCombo As Object, nomCol As String)
Dim lig As Long
Dim nbElement As Integer
Dim trouveElm As Boolean
LCombo.Clear
' Boucle de la ligne 2 à la dernière ligne dans la colonne nomCol
For lig = 2 To Range(nomCol & Cells.Rows.Count).End(xlUp).Row
trouveElm = False
' Vérifier que l'élément à ajouter dans la liste n'existe pas déjà
For nbElement = 0 To LCombo.ListCount - 1
' L'élément est déjà présent dans la liste, sortie de la boucle
If LCombo.List(nbElement) = Range(nomCol & lig).Value Then
trouveElm = True
Exit For
End If
Next nbElement
' Elément non trouvé dans la liste, l'ajouter
If trouveElm = False Then LCombo.AddItem Range(nomCol & lig).Value
Next lig
End Sub |
Partager