Option Explicit
Dim WS As Worksheet 'Variable pour un Objet Worksheet en PUBLIC pour tous les Controls de ce UserForm
Private Sub Ini()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L As Long 'Variable pour connaitre le numéro de derniere ligne
Dim i, y As Integer 'Variable pour connaitre incrémenter les Data
'On Vide tous les Controls Combobox
For Each CTRL In Me.Controls
If TypeOf CTRL Is MSForms.ComboBox Then CTRL.Clear
Next CTRL
Set WS = ThisWorkbook.Worksheets("PARAMETRE") 'On identifie l'objet pour la feuille de travail
'Pour éviter les fash d'écran pour le select ci dessous
Application.ScreenUpdating = False
'WS.Select 'On sélectionne la feuille sinon bug si elle ne l'est pas
For y = 1 To 31
Select Case y
Case 1 To 11, 15 To 27, 30 To 31
L = WS.Cells(Cells.Rows.Count, y).End(xlUp).Row
For i = 2 To L 'Boucle sur lignes de la feuille :2 jusqu'à dernière
With Me.Controls("ComboBox" & y)
.AddItem WS.Cells(i, y) 'On ajoute dans les ComboBox toutes les valeurs, cellules après cellules
End With
Next
End Select
Next y
Application.ScreenUpdating = True
End Sub
Private Sub BoutQuitte_Click()
Unload Me
End Sub
Private Sub CmdAjout_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L, y As Integer 'Variable pour connaitre le numéro de derniere ligne vide
Dim LeChoix As String
L = ThisWorkbook.Worksheets("BDD").Range("A65536").End(xlUp).Row + 1 ' On identifie la dernière ligne vide en partant du bas
For y = 1 To 31
Select Case y
Case 1 To 11
With F1
.Cells(L, y) = Me.Controls("ComboBox" & y).Value
End With
Case 12
LeChoix = Switch(Me.OptionButton4, "oui", Me.OptionButton5, "Non")
F1.Cells(L, y) = LeChoix
Case 13
LeChoix = Switch(Me.OptionButton10, "Homme", Me.OptionButton11, "Femme")
F1.Cells(L, y) = LeChoix
Case 14
LeChoix = Switch(Me.OptionButton12, "Homme", Me.OptionButton13, "Femme")
F1.Cells(L, y) = LeChoix
Case 15 To 27
With F1
.Cells(L, y) = Me.Controls("ComboBox" & y).Value
End With
Case 28
LeChoix = Switch(Me.OptionButton14, "Conforme", Me.OptionButton15, "Non Conforme")
F1.Cells(L, y) = LeChoix
Case 29
LeChoix = Switch(Me.OptionButton16, "Conforme", Me.OptionButton17, "Non Conforme")
F1.Cells(L, y) = LeChoix
Case 30 To 31
With F1
.Cells(L, y) = Me.Controls("ComboBox" & y).Value
End With
End Select
Next y
Dim Ctr As Control, col As Integer, lig As Long
With Worksheets("PARAMETRE")
For Each Ctr In Me.Controls
If TypeName(Ctr) = "ComboBox" Then
If Ctr.ListIndex = -1 And Ctr.Value <> "" Then
col = Right(Ctr.Name, Len(Ctr.Name) - 8)
lig = .Cells(Cells.Rows.Count, col).End(xlUp).Row + 1
.Cells(lig, col) = Ctr
End If
End If
Next
End With
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
End Sub
A L 'activation on démarre le focus sur la Première Combobox
Private Sub ComboBox1_Change()
ComboBox1.List = Intersect(Feuil2.[A2:A1000000], Feuil2.UsedRange).Value
End Sub
Private Sub ComboBox25_Change()
If UCase(ComboBox25) = "OUI" Then ComboBox26.Visible = True
End Sub
Private Sub UserForm_Activate()
Me.ComboBox1.SetFocus
End Sub
Private Sub UserForm_Initialize()
Dim TE(), TS(), L As Long
TE = Feuil2.UsedRange.Resize(, 2).Value
ReDim TS(0 To UBound(TE, 1) - 2)
For L = 2 To UBound(TE, 1)
TS(L - 2) = Format(TE(L, 1) + TE(L, 2), "dd/mm/yyyy hh:mm")
Next L
Me.ComboBox1.List = TS
Ini
ComboBox26.Visible = False
End Sub