Sub test_A()
Dim ligne&
Range("A1").FormulaR1C1 = "8/1/2022"
Range("A2").Formula = "=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(EOMONTH(A1,-1)+1&"":""&EOMONTH(A1,0))))=2)*1)-1+(WEEKDAY(EOMONTH(A1,0),2)>0)*1"
Rows("3:500").Clear
Range("B3:P" & Application.RandBetween(3, 25)).Formula = "=RaND()"
a = [A2]
ligne = Cells(Rows.Count, 2).End(3).Row
Set plage_graph = Range(Cells(3, 2), Cells(ligne, IIf(a = 4, 13, 16)))
MsgBox plage_graph.Address
End Sub
Sub test_B()
Dim ligne&
Range("A1").FormulaR1C1 = "7/1/2022"
Range("A2").Formula = "=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(EOMONTH(A1,-1)+1&"":""&EOMONTH(A1,0))))=2)*1)-1+(WEEKDAY(EOMONTH(A1,0),2)>0)*1"
Rows("3:500").Clear
Range("B3:P" & Application.RandBetween(3, 25)).Formula = "=RaND()"
a = [A2]
ligne = Cells(Rows.Count, 2).End(3).Row
Set plage_graph = Range(Cells(3, 2), Cells(ligne, IIf(a = 4, 13, 16)))
MsgBox plage_graph.Address
End Sub