Salut tout le monde, j'ai besoin d'aide pour mon code qui sert a faire la moyenne pondéré. si tout les colonnes de la selection des coefficients est nul ou vide ; la moyenne pondéré sera egale à 0 sinon il aura le calcule normal.
voici mon code
Sub ponderee()
Dim limit As Range
Dim rating As Range
Set rating = Range("B2", Range("B1").End(xlDown))
Set limit = Range("A2", Range("A1").End(xlDown))
Sheets("Feuil1").Range("F5").Value = MoyennePonderee(rating, limit)
End Sub
Function MoyennePonderee(Notes As Range, Coeff As Range) As Double
Dim n As Integer, i As Integer, Moy As Double, SomCoeff As Double
n = Notes.Cells.Count
For i = 1 To n
If IsEmpty(Coeff.Cells(i)) Then
Moy = 0
SomCoeff = 0
MoyennePonderee = 0
ElseIf (Not IsEmpty(Notes.Cells(i)) And IsNumeric(Notes.Cells(i).Value)) Then
Moy1 = Moy + Coeff.Cells(i).Value * Notes.Cells(i).Value
SomCoeff1 = SomCoeff + Coeff.Cells(i).Value
MoyennePonderee = Round(Moy / SomCoeff, 0)
End If
Next i
End Function
Je compte sur vous les gars
et merci d'avance