Function CalculUnités(colRef As Range, colDate As Range, ProdJourMois As Range, Optional choix As Byte) As Variant
'choix = 0 pour colonne C, choix = 1 pour colonne D, choix = 2 pour colonne E, choix = 3 pour colonne F, choix = 4 pour colonne G
Dim c As Range, derlig&, deb&, fin&, Res As Double, j&
Set c = Application.Caller
derlig = colRef(colRef.Rows.Count).End(xlUp).Row
CalculUnités = ""
If c.Row = 1 And choix <> 3 Or c.Row > derlig Or colRef(c.Row) <> "" And choix <> 3 Then Exit Function
For deb = c.Row - 1 To 1 Step -1
If colRef(deb) <> "" Then Exit For
Next deb
If deb = 0 And choix <> 3 Then Exit Function
If choix = 1 Then
fin = c.Row
ElseIf choix < 3 Then
For fin = c.Row + 1 To derlig
If colRef(fin) <> "" Then Exit For
Next fin
If fin > derlig Then Exit Function
End If
If choix = 2 Then
Res = colRef(fin) - colRef(deb)
ElseIf choix = 3 Then
If colRef(c.Row) = "" Then Res = c(1, 0) * c(1, -1) / c(1, -2) + colRef(deb) Else Res = colRef(c.Row)
ElseIf choix = 4 Then
If colRef(c.Row) = "" Then CalculUnités = "=E" & c.Row & "*D" & c.Row & "/C" & c.Row & "+B" & deb
Exit Function
Else
For j = colDate(deb) + 1 To colDate(fin)
Res = Res + ProdJourMois(Month(j))
Next j
End If
CalculUnités = Res
End Function