Private Sub CommandButton1_Click()
'Compter le nombre de CheckBox
Dim Ctrl As Control, Cpt As Integer
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then Cpt = Cpt + 1
Next Ctrl
Dim NbAnnee As Long
NbAnnee = Application.CountA(Range("S:S"))
Dim o As Long
o = 1
For q = NbAnnee To 1 Step -1
Sheets("Board").Cells(10, o + 6) = Sheets("Board").Range("S" & q).Value
Sheets("Board").Cells(10, o + 6).Interior.ColorIndex = 27
Sheets("Board").Cells(10, o + 6).Font.ColorIndex = 1
o = o + 1
Next
NbAnnee = Application.CountA(Range("S:S"))
'-------------------------------------------------------------------------------
'NbColonne = Application.CountA(Range("S:S"))
'ResultV = Application.WorksheetFunction.VLookup(NomCheckBox, Sheets("2022").Range("B6:S103"), g, 0)
Dim a As Long 'Numéro de ligne
If UserForm2.Code = "F" Then
Sheets("board").Range("AA1:AZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("AA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
Dim NbTrue As Long
NbTrue = Application.CountA(Range("AA:AA"))
Dim NbColonne As Long
Dim NbLigne As Long
Dim ValCaption As Variant
Dim ValResult As Long
Dim MonTableau As Variant
Dim MonAnnee As Variant
Dim Somme As Long
MonTableau = Sheets("Board").Range("H4")
MonAnnee = Sheets("Board").Range("H6")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("AA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range("B6:S104"), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 27) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(11, NbColonne + 6) = Somme
End If
Next n
'-------------------------------------------------------------------------------
ElseIf UserForm2.Code = "P" Then
Sheets("board").Range("BA1:BZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("BA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
NbTrue = Application.CountA(Range("BA:BA"))
MonTableau = Sheets("Board").Range("H4")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("BA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range(MonTableau), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 53) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(12, NbColonne + 6) = Somme
End If
Next n
'-------------------------------------------------------------------------------
ElseIf UserForm2.Code = "L" Then
Sheets("board").Range("CA1:CZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("CA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
NbTrue = Application.CountA(Range("CA:CA"))
MonTableau = Sheets("Board").Range("H4")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("CA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range(MonTableau), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 79) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(13, NbColonne + 6) = Somme
End If
Next n
'-------------------------------------------------------------------------------
ElseIf UserForm2.Code = "Q" Then
Sheets("board").Range("DA1:DZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("DA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
NbTrue = Application.CountA(Range("DA:DA"))
MonTableau = Sheets("Board").Range("H4")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("DA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range(MonTableau), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 105) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(14, NbColonne + 6) = Somme
End If
Next n
'-------------------------------------------------------------------------------
ElseIf UserForm2.Code = "R" Then
Sheets("board").Range("EA1:EZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("EA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
NbTrue = Application.CountA(Range("EA:EA"))
MonTableau = Sheets("Board").Range("H4")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("EA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range(MonTableau), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 131) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(15, NbColonne + 6) = Somme
End If
Next n
'-------------------------------------------------------------------------------
ElseIf UserForm2.Code = "M" Then
Sheets("board").Range("FA1:FZ30").Clear
a = 1
For t = 1 To Cpt
If Controls("CheckBox" & t) Then
Sheets("board").Range("FA" & a) = Controls("CheckBox" & t).Caption
a = a + 1
End If
Next
NbTrue = Application.CountA(Range("FA:FA"))
MonTableau = Sheets("Board").Range("H4")
For n = 1 To NbAnnee
NbColonne = n
Somme = 0
For j = 1 To NbTrue
NbLigne = j
ValCaption = Sheets("board").Range("FA" & NbLigne).Value
ValResult = Application.WorksheetFunction.VLookup(ValCaption, Sheets("2022").Range(MonTableau), NbColonne + 2, 0)
Sheets("Board").Cells(NbLigne, NbColonne + 157) = ValResult
Somme = Somme + ValResult
Next j
If NbTrue = o Then
MsgBox "Aucun code analytique selectionné"
Unload UserForm1
Exit For
Else
Sheets("Board").Cells(16, NbColonne + 6) = Somme
End If
Next n
End If
'-------------------------------------------------------------------------------
Unload UserForm1
Unload UserForm2
MsgBox "Formule modifiée"
End Sub
Private Sub CommandButton2_Click()
Unload UserForm1
End Sub