[COLOR="DarkSlateGray"][B]Function moy(nSem$, dateRef As Range, valRef As Range)
[COLOR="SeaGreen"]'
'Arguments :
' nSem$ : référence à une semaine au format normalisé.
' dateRef As Range : plage des dates.
' valRef As Range : plage des consommations.
'
'Utilise la fonction semaine.
'[/COLOR]
Application.Volatile
Dim i&, j&, s#, oDate, oVal
moy = ""
If dateRef.Count = valRef.Count Then
oDate = dateRef.Value
oVal = valRef.Value
For i = 1 To UBound(oDate, 1)
If IsDate(oDate(i, 1)) And IsNumeric(oVal(i, 1)) And oVal(i, 1) <> "" Then
If semaine(CDate(oDate(i, 1))) = nSem Then s = s + oVal(i, 1): j = j + 1
End If
Next i
If j > 0 Then moy = s / j
End If
End Function
Function semaine(d As Date) As String
Application.Volatile
Dim ns&
d = Int(d)
ns = DateSerial(Year(d + (8 - Weekday(d, vbSunday)) Mod 7 - 3), 1, 1)
ns = ((d - ns - 3 + (Weekday(ns, vbSunday) + 1) Mod 7)) \ 7 + 1
semaine = Year(d) - (ns > 50) * (Month(d) = 1) + (ns < 5) * (Month(d) = 12) & "-W" & Right$("0" & ns, 2)
End Function[/B][/COLOR]