Private Sub UserForm_Initialize()
Dim sh As Worksheet
Dim Niveau As String
Dim i As Integer
For Each sh In ThisWorkbook.Worksheets
If sh.Name Like "Niveau*" Then
Niveau = Trim(Left(sh.Name, InStr(1, sh.Name, "Séance") - 1))
If ComboBox1.ListCount = 0 Then
ComboBox1.AddItem Niveau
Else
ComboBox1.Text = Niveau
If ComboBox1.ListIndex = -1 Then
For i = 0 To ComboBox1.ListCount - 1
If CInt(Split(ComboBox1.List(i), " ")(1)) > CInt(Split(Niveau, " ")(1)) Then Exit For
Next
ComboBox1.AddItem Niveau, i
End If
End If
End If
Next
'Premier élément de liste pas défaut
If ComboBox1.ListCount > 0 Then ComboBox1.ListIndex = 0
'CommandButton1.Enabled = ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1
End Sub
Private Sub ComboBox1_Click()
Dim sh As Worksheet
Dim Séance As String, tmp As Variant
Dim i As Integer
If ComboBox1.ListIndex > -1 Then
ComboBox2.Clear
For Each sh In ThisWorkbook.Worksheets
If sh.Name Like ComboBox1.Value & "*" Then
'Extraction de la séance dans le nom
Séance = Trim(Right(sh.Name, Len(sh.Name) - Len(ComboBox1.Value) - 1))
ComboBox2.Text = Séance
'En changeant la propriété .Text du combobox si l'item exite déjà .listIndex sera >-1
If ComboBox2.ListIndex = -1 Then
If ComboBox2.ListCount > 0 Then
'Boucle à la recherche de la bonne position
'déterminée par la valeur du numéro de séance
For i = 0 To ComboBox2.ListCount - 1
If CInt(Split(ComboBox2.List(i), " ")(1)) > CInt(Split(Séance, " ")(1)) Then Exit For
Next
End If
ComboBox2.AddItem Séance, i
End If
End If
Next
End If
'Premier élément de liste par défaut
If ComboBox2.ListCount > 0 Then ComboBox2.ListIndex = 0
End Sub