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
|
Option Explicit
Const LIGNE_DEBUT_LISTE As Integer = 2 'Commence à la ligne 2 car la première ligne est la légende (N°, prenom, nom1, date_naissance)
Const LIGNE_FIN_LISTE As Integer = 70 'est la limite à modifier en fonction de la longueur de la liste du tableau Excel
Const COLONNE_Nº As Integer = 1
Const COLONNE_PRENOM As Integer = 2
Const COLONNE_Nom As Integer = 3
Const COLONNE_datenaissance As Integer = 4
Dim iLigne As Integer
Private Sub UserForm_Initialize() 'au lieu de : Private Sub Anniv_Initialize()
With ThisWorkbook.Sheets(3) 'ou : With ThisWorkbook.Sheets("BD1") au lieu de : With ThisWorkbook.Sheets(BD1)
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "20;60;60"
For iLigne = LIGNE_DEBUT_LISTE To LIGNE_FIN_LISTE
ListBox1.AddItem
ListBox1.List(iLigne - LIGNE_DEBUT_LISTE, 0) = .Cells(iLigne, COLONNE_Nº).Value
ListBox1.List(iLigne - LIGNE_DEBUT_LISTE, 1) = .Cells(iLigne, COLONNE_PRENOM).Value
ListBox1.List(iLigne - LIGNE_DEBUT_LISTE, 2) = .Cells(iLigne, COLONNE_Nom).Value
Next iLigne
End With
ListBox1.Selected(0) = True
End Sub
Private Sub ListBox1_Click()
For iLigne = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(iLigne) = True Then
datenaissance = ThisWorkbook.Sheets(3).Cells(iLigne + LIGNE_DEBUT_LISTE, COLONNE_datenaissance).Value 'datenaissance = ... au lieu de : TextBox_datenaissance = ... car le TextBox se nomme : datenaissance
End If
Next iLigne
End Sub |