Function MoyenneSi(ByVal Plage As Range, ByVal Critere As String, Optional ByVal SommePlage As Range) As Double
Dim Som As Double
Dim Nb As Double
'----------------- Récupèrations des valeurs par Worksheetfunction----------------------------
Som = WorksheetFunction.SumIf(Plage, Critere, SommePlage)
Nb = WorksheetFunction.CountIf(Plage, Critere)
'------------------------------------- Renvoi ------------------------------------------------
[SIZE=3][COLOR=red] If Nb > 0 Then MoyenneSi = Som / Nb[/COLOR][/SIZE]
End Function
Sub Moyenne()
Dim i As Long
Dim j As Long
Dim colonnemax As Long
Cells(9, 4).Select
colonnemax = ActiveCell.Column
For i = 9 To 73
For j = 4 To colonnemax
Sheets("notes").Cells(i, 4).Value = MoyenneSi(Sheets("notes").Cells(i, j), Sheets("notes").Cells(8, j).Value = pierre, Sheets("bibliothèque de note").Cells(i, 4))
Next j
Next i
End Sub