1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Sub calculmoyenne()
Dim f As Worksheet
Dim ligne As Integer, nbr As Integer, nbrfin As Integer
Dim compt As Integer
Dim res As Long
Set f = ActiveWorkbook.ActiveSheet.Name
ligne = 4
While ligne < 50
compt = ligne
nbr = 0
While (f.Name.Cells(compt, 4).Value = f.Name.Cells(compt + 1, 4).Value)
compt = compt + 1
nbr = nbr + 1
Wend
res = calculmoyenne1(f, nbr, ligne)
nbrfin = nbr + ligne
f.Cells(nbrfin, 10).Value = res
ligne = compt
Wend
End Sub
Function calculmoyenne1(nomF As Worksheet, nombre As Integer, ligne As Integer) As Long
Dim i As Integer
Dim ajout As Long
Dim f As Worksheet
Dim nombrefin As Integer
Set f = Worksheets(nomF)
ajout = 0
nombrefin = nombre + ligne
For i = ligne To nombrefin
ajout = ajout + f.Cells(i, 8).Value
Next i
calculmoyenne = ajout / nombre
End Function |
Partager