Public d As Object 'mémorise la variable
Function MFC(cel As Range, feries As Range) As Double
Dim a, b, c, maxi%, tablo, tabdat, col%, dat&, nn%, i As Variant
a = Array("E", "D", "P") 'modifiable
b = Array(5, 20, 20) 'modifiable
c = Array(0.6, 0.25, 0.25) 'modifiable
maxi = Application.Max(b)
If d Is Nothing Then Dico
tablo = cel.Parent.Cells(cel.Row, 1).Resize(, cel.Column) 'matrice, plus rapide
tabdat = cel.Parent.Cells(6, 1).Resize(, cel.Column).Value2 'dates en ligne 6
For col = UBound(tablo, 2) To 1 Step -1
dat = Val(tabdat(1, col))
If Weekday(dat, 2) < 6 And Not d.exists(dat) Then
nn = nn + 1
If nn > maxi Then Exit Function
If tablo(1, col) <> "" Then
i = Application.Match(tablo(1, col), a, 0)
If IsNumeric(i) Then If nn <= b(i - 1) Then MFC = c(i - 1)
Exit Function
End If
ElseIf nn = 0 Then
Exit Function 'si samedi, dimanche ou jour férié
End If
Next
End Function
Function Charge_Journaliere(r As Range, feries As Range)
For Each r In r
Charge_Journaliere = Charge_Journaliere + MFC(r, feries)
Next
End Function
Sub Dico()
Dim c As Range
Set d = CreateObject("Scripting.Dictionary")
For Each c In [Références!B2:B16]
d(c.Value2) = ""
Next
End Sub