'### Constantes à adapter ###
Const ROW_BASE As Long = 4 ' 4ème ligne
Const COL_BASE_CUMUL As Long = 6 ' 6ème colonne = "F"
'°°° La colonne "code F" doit être voisine et précéder la colonne " Q " °°°
Const COL_CODEF As Long = 2 ' 2ème colonne ET inclusion de la 3ème colonne " Q "
'############################
Function CUMUL(Base As Range) As Variant
Dim S As Worksheet
Dim R As Range
Dim C As Range
Dim x#
Application.Volatile
Set S = Sheets(Base.Parent.Name)
Set R = S.Range(S.Cells(ROW_BASE, COL_BASE_CUMUL), _
S.Cells(Range("a" & ROW_BASE & "").End(xlDown).Row, COL_BASE_CUMUL))
For Each C In R
If IsNumeric(C) Then x# = x# + C
Next C
If x# <> 0 Then
CUMUL = x#
Else
CUMUL = vbNullString
End If
End Function
Function NBCOMMANDES(Base As Range) As Variant
Dim S As Worksheet
Dim R As Range
Dim var
Dim i&
Dim j&
Dim T()
Application.Volatile
Set S = Sheets(Base.Parent.Name)
Set R = S.Range(S.Cells(ROW_BASE, COL_CODEF), _
S.Cells(Range("a" & ROW_BASE & "").End(xlDown).Row, COL_CODEF + 1))
var = R
For i& = 1 To UBound(var, 1)
If var(i&, 1) = Base Then
j& = j& + 1
ReDim Preserve T(1 To j&)
T(j&) = var(i&, 2)
End If
Next i&
j& = 0
Do
If T(UBound(T)) <> "" Then j& = j& + 1
For i& = UBound(T) - 1 To 1 Step -1
If T(i&) = T(UBound(T)) Then T(i&) = ""
Next i&
If UBound(T) = 1 Then Exit Do
ReDim Preserve T(1 To UBound(T) - 1)
Loop
NBCOMMANDES = vbNullString
If Base.Row = 1 Then Exit Function
If j& > 0 And Base <> Base.Offset(-1, 0) Then NBCOMMANDES = j&
End Function