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
| Private Sub UserForm_Initialize()
Dim tbStruc As ListObject, colNP As Long, rNP As Range, c As Range, c1 As String
Set tbStruc = SheetASSOC.ListObjects("tblMembres")
tbStruc.Range.AutoFilter 'ôter les filtres éventuels
colNP = tbStruc.ListColumns("Nom & Prénom").Index
CBoxMembres.Clear
'CBoxMembres.List = tbStruc.ListColumns(colNP).DataBodyRange.Value '--- liste inutilisable à cause des doublons !
Set rNP = tbStruc.ListColumns(colNP).DataBodyRange '--- plage Nom & Prénom
c1 = rNP(1, 1).Address '--- adresse première cellule de la plage
For Each c In rNP
Debug.Print Evaluate("=COUNTIF(" & c1 & ":" & c.Address & ", " & c.Address & ")")
If Evaluate("=COUNTIF(" & c1 & ":" & c.Address & ", " & c.Address & ")") = 1 Then
CBoxMembres.AddItem c.Value
End If
Next c
Set tbStruc = Nothing
End Sub
Private Sub CBoxMembres_Change()
Dim tbStruc As ListObject, colAn As Long, AnneesTrouvees As Range, rAnnee As Range
'charge les années avec ce nom
Set tbStruc = SheetASSOC.ListObjects("tblMembres")
colAn = tbStruc.ListColumns("Année").Index
tbStruc.Range.AutoFilter 'ôter les filtres éventuels
tbStruc.Range.AutoFilter tbStruc.ListColumns("Nom & Prénom").Index, CBoxMembres 'tri sur les nom & prénom renvoyé depuis CBoxMembres
Set AnneesTrouvees = tbStruc.ListColumns(colAn).DataBodyRange.SpecialCells(xlCellTypeVisible)
CBoxYear.Clear
For Each rAnnee In AnneesTrouvees
CBoxYear.AddItem rAnnee.Value
Next rAnnee
Set rAnnee = Nothing
Set tbStruc = Nothing
Set AnneesTrouvees = Nothing
End Sub
Private Sub CBoxYear_Change()
Dim tbStruc As ListObject, colAn As Long, ligneAn As Long, AnneesTrouvees As Range, rAnnee As Range
FrmInfos.Enabled = True 'rend accessible la deuxieme partie de l'USF (modifiable par l'utilisateur)
'charge le nom indiqué (cboxMembres) pour l'année sélectionnée
Set tbStruc = SheetASSOC.ListObjects("tblMembres")
colAn = tbStruc.ListColumns("Année").Index
tbStruc.Range.AutoFilter 'ôter les filtres éventuels
tbStruc.Range.AutoFilter tbStruc.ListColumns("Nom & Prénom").Index, CBoxMembres 'tri sur les nom & prénom renvoyé depuis CBoxMembres
'Debug.Print CBoxYear.ListIndex, CBoxYear
On Error Resume Next '--- erreur si aucune année sélectionnée
ligneAn = tbStruc.ListColumns(colAn).DataBodyRange.SpecialCells(xlCellTypeVisible).Find(CBoxYear).Row
ligneAn = ligneAn - tbStruc.Range.Rows(1).Row
TxtBoxNom = tbStruc.ListColumns("Nom").DataBodyRange(ligneAn).Value
TxtBoxPrenom = tbStruc.ListColumns("Prénom").DataBodyRange(ligneAn).Value
Set tbStruc = Nothing
End Sub |
Partager