Private Sub UserForm_Initialize()
Dim FEUILLE As Worksheet
Me.ComboBox1.AddItem "Choix Corps d'Etat"
For Each FEUILLE In ThisWorkbook.Worksheets
If FEUILLE.Name <> "ACCUEIL" Then
With Me.ComboBox1
.AddItem FEUILLE.Name
.Value = .List(0)
End With
End If
Next
Worksheets("électricité").Activate ' Elle va servir de Base pour établir les Colonnes (Faute de mieux, ou plus lourd à gérer!!)
With UserForm1.ListView1: .View = 3: .Gridlines = True: .FullRowSelect = True: .Sorted = False
With .ColumnHeaders
For i = 1 To 20 '"20" étant un nombre forfaitaire de Colonnes renseignées .... On peut l'adapter!
If ActiveSheet.Cells(1, i).Value <> "" Then
.Add , , ActiveSheet.Cells(1, i).Value, (ActiveSheet.Columns(i).ColumnWidth * 4) + 18
'"4" étant issu des tests (Voire Inches et Points), et "+ 18" un correctif de la même origine.
End If
Next i
End With
End With
End Sub
Private Sub ComboBox1_Change()
Me.Label1.Caption = Me.ComboBox1.Value
Me.ListView1.ListItems.Clear
For Each FEUILLE In ThisWorkbook.Worksheets
If FEUILLE.Name = Me.ComboBox1.Value And FEUILLE.Name <> "ACCUEIL" Then
FEUILLE.Activate
With Me.ListView1
For i = 2 To ActiveSheet.Cells(65536, 2).End(xlUp).Row
If ActiveSheet.Cells(i, 1).Value <> "" Then
.ListItems.Add , , ActiveSheet.Cells(i, 1).Value
Else
.ListItems.Add , , "Sans Code"
End If
For j = 2 To .ColumnHeaders.Count
If ActiveSheet.Cells(i, j).Value <> "" Then
.ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(i, j).Value
Else
.ListItems(.ListItems.Count).ListSubItems.Add , , "?"
End If
Next j
Next i
End With
End If
Next
End Sub