Calculer Moyenne Worksheetfunxtion

Bonjour,

je souhaite calculer une serie de moyenne pour cela j'utilise Worksheetfunction.average cependant mon code ne marche pas

si quelqu'un pouvait m'aider

merci

Sub Mac()

Dim FL1, FLZ1, FLZ2, FLZ3 As Worksheet, NoCol As Integer
Dim NoLig, NoLigZ1, NoLigZ2, NoLigZ3, NoLig1, NoLig2 As Long, Var As Variant

    Set FL1 = Worksheets(1)
    Set FL2 = Worksheets(2)
    Set FLZ2 = Worksheets(3)
    'Set FLZ3 = Worksheets(4)

    NoLigZ1 = 1
    NoLigZ2 = 1
    NoLigZ3 = 1
    NoCol = 1 'lecture de la colonne 1

        For NoLig1 = 2 To Split(FL1.UsedRange.Address, "$")(4)
FLZ1.Cells(NoLigZ1, 7).Value = Application.WorksheetFunction.Average(FLZ1.Range(FLZ1.Cells(NoLigZ1, 7), Cells(NoLigZ1 + 100, 7)))

Next
End Sub

Bonjour,

C'est quoi FLZ1 ?

FLZ1.Cells(NoLigZ1, 7).Value = Application.WorksheetFunction.Average(FLZ1.Range(FLZ1.Cells(NoLigZ1, 7), (????FLZ1????).Cells(NoLigZ1 + 100, 7)))

A+

c'est une erreur de ma part que je viens de rectifier

cependant j,ai toujours une erreur sur ma boucle

ils disent l'indice n'appartient pas à la selection

Sub Mac()

Dim FL1, FLZ1, FLZ2, FLZ3 As Worksheet, NoCol As Integer
Dim NoLig, NoLigZ1, NoLigZ2, NoLigZ3, NoLig1, NoLig2 As Long, Var As Variant

    Set FL1 = Worksheets(1)
    Set FL2 = Worksheets(2)
    Set FLZ2 = Worksheets(3)
    'Set FLZ3 = Worksheets(4)

    NoLigZ1 = 1
    NoLigZ2 = 1
    NoLigZ3 = 1
    NoCol = 1 'lecture de la colonne 1

        For NoLig1 = 2 To Split(FL1.UsedRange.Address, "$")(4)
FL1.Cells(NoLig1, 7).Value = Application.WorksheetFunction.Average(FL1.Range(FL1.Cells(NoLig1, 2), Cells(NoLig1 + 100, 2)))

Next
End Sub

quelqu'un a une idée?

En bonne logique vers la fin ton

...Cells(NoLig1 + 100, 2))) devrait aussi avoir un FL1 :

FL1.Cells(NoLig1 + 100, 2)))

... mais ce n'est pas cela qui fait planter :

On peut penser que c'est le "Split(FL1.UsedRange.Address, "$")(4)" qui doit indiquer un N° de ligne inattendu.

Pour vérifier modifie la macro comme suit :

Sub Mac()
Dim FL1, FLZ1, FLZ2, FLZ3 As Worksheet, NoCol As Integer
Dim NoLig, NoLigZ1, NoLigZ2, NoLigZ3, NoLig1, NoLig2 As Long, Var As Variant
Dim k&    

    Set FL1 = Worksheets(1)
    Set FL2 = Worksheets(2)
    Set FLZ2 = Worksheets(3)
    'Set FLZ3 = Worksheets(4)

    NoLigZ1 = 1
    NoLigZ2 = 1
    NoLigZ3 = 1
    NoCol = 1 'lecture de la colonne 1

k=Split(FL1.UsedRange.Address, "$")(4)
Msgbox k

        For NoLig1 = 2 To k
FL1.Cells(NoLig1, 7).Value = Application.WorksheetFunction.Average(FL1.Range(FL1.Cells(NoLig1, 2), Cells(NoLig1 + 100, 2)))

Next
End Sub

Je pense que ton MsgBox révèlera une dernière ligne inappropriée. (Il faut toujours être circonspect avec UsedRange !)

C'est pourquoi, pour récupérer la dernière ligne, on utilise plutôt la formule :

i=Cells(Rows.Count, 1).End(xlUp).Row

Si c'est pas ça fournir le classeur KIVABIEN avec.

A+

pas envie de dire bonjour,

Merci de m'avoir si aimablement répondu sur ton message sur le même sujet. Peux-tu le clôturer ?

https://forum.excel-pratique.com/excel/erreur-1004-erreur-definie-par-l-application-ou-par-l-objet-t52525.html

Bonjour

je suis désolé hso4 je n'avais pas vu votre message sur l'autre page

je rencontre un autre probleme dans mon code alors qu'hier il fonctionnait parfaitement

c'est ecrit erreur définie par l'application ou par l'objet

Dim FL1, FLZ1, FLZ2, FLZ3 As Worksheet, NoCol As Integer
Dim NoLig, NoLigZ1, NoLigZ2, NoLigZ3 As Long, Var As Variant

    Set FL1 = Worksheets(1)
    Set FLZ1 = Worksheets(2)
    Set FLZ2 = Worksheets(3)
    Set FLZ3 = Worksheets(4)

    NoLigZ1 = 1
    NoLigZ2 = 1
    NoLigZ3 = 1
    NoCol = 1 'lecture de la colonne 1
    For NoLig = 1 To Split(FL1.UsedRange.Address, "$")(4)
        If FL1.Cells(NoLig, NoCol) = 1 Then
        FLZ1.Rows(NoLigZ1).Value = FL1.Rows(NoLig).Value
        NoLigZ1 = NoLigZ1 + 1
        End If
        If FL1.Cells(NoLig, NoCol) = 2 Then
        FLZ2.Rows(NoLigZ2).Value = FL1.Rows(NoLig).Value
        NoLigZ2 = NoLigZ2 + 1
        End If
        If FL1.Cells(NoLig, NoCol) = 3 Then
        FLZ3.Rows(NoLigZ3).Value = FL1.Rows(NoLig).Value
        NoLigZ3 = NoLigZ3 + 1
        End If
    Next

     'Masquer des colonnes
    FLZ1.Select
    Columns("B:D").Select
    Selection.EntireColumn.Hidden = True

    FLZ2.Select
    Columns("B:D").Select
    Selection.EntireColumn.Hidden = True

    FLZ3.Select
    Columns("B:D").Select
    Selection.EntireColumn.Hidden = True

    'FeuilleZone1
    'Moyenne
    FLZ1.Cells(NoLigZ1, 1).Value = "Moyenne"
    FLZ1.Cells(NoLigZ1, 7).Value = WorksheetFunction.Average(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))
    FLZ1.Cells(NoLigZ1, 8).Value = WorksheetFunction.Average(FLZ1.Range(Cells(1, 8), Cells(NoLigZ1, 8)))
    FLZ1.Cells(NoLigZ1, 9).Value = WorksheetFunction.Average(FLZ1.Range(Cells(1, 9), Cells(NoLigZ1, 9)))
    FLZ1.Cells(NoLigZ1, 10).Value = WorksheetFunction.Average(FLZ1.Range(Cells(1, 10), Cells(NoLigZ1, 10)))

    'ecart-type
    FLZ1.Cells(NoLigZ1 + 1, 1).Value = "ecart-type"
    FLZ1.Cells(NoLigZ1 + 1, 7).Value = WorksheetFunction.StDev(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))
    FLZ1.Cells(NoLigZ1 + 1, 8).Value = WorksheetFunction.StDev(FLZ1.Range(Cells(1, 8), Cells(NoLigZ1, 8)))
    FLZ1.Cells(NoLigZ1 + 1, 9).Value = WorksheetFunction.StDev(FLZ1.Range(Cells(1, 9), Cells(NoLigZ1, 9)))
    FLZ1.Cells(NoLigZ1 + 1, 10).Value = WorksheetFunction.StDev(FLZ1.Range(Cells(1, 10), Cells(NoLigZ1, 10)))

    'variance
    FLZ1.Cells(NoLigZ1 + 2, 1).Value = "variance"
    FLZ1.Cells(NoLigZ1 + 2, 7).Value = WorksheetFunction.Var(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))
    FLZ1.Cells(NoLigZ1 + 2, 8).Value = WorksheetFunction.Var(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))
    FLZ1.Cells(NoLigZ1 + 2, 9).Value = WorksheetFunction.Var(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))
    FLZ1.Cells(NoLigZ1 + 2, 10).Value = WorksheetFunction.Var(FLZ1.Range(Cells(1, 10), Cells(NoLigZ1, 10)))

    'FeuilleZone2

    'Moyenne
    FLZ2.Cells(NoLigZ2, 1).Value = "Moyenne"
    FLZ2.Cells(NoLigZ2, 7).Value = WorksheetFunction.Average(FLZ2.Range(Cells(1, 7), Cells(NoLigZ2, 7)))
    FLZ2.Cells(NoLigZ2, 8).Value = WorksheetFunction.Average(FLZ2.Range(Cells(1, 8), Cells(NoLigZ2, 8)))
    FLZ2.Cells(NoLigZ2, 9).Value = WorksheetFunction.Average(FLZ2.Range(Cells(1, 9), Cells(NoLigZ2, 9)))
    FLZ2.Cells(NoLigZ2, 10).Value = WorksheetFunction.Average(FLZ2.Range(Cells(1, 10), Cells(NoLigZ2, 10)))

    'ecart-type
    FLZ2.Cells(NoLigZ2 + 1, 1).Value = "ecart-type"
    FLZ2.Cells(NoLigZ2 + 1, 7).Value = WorksheetFunction.StDev(FLZ2.Range(Cells(1, 7), Cells(NoLigZ2, 7)))
    FLZ2.Cells(NoLigZ2 + 1, 8).Value = WorksheetFunction.StDev(FLZ2.Range(Cells(1, 8), Cells(NoLigZ2, 8)))
    FLZ2.Cells(NoLigZ2 + 1, 9).Value = WorksheetFunction.StDev(FLZ2.Range(Cells(1, 9), Cells(NoLigZ2, 9)))
    FLZ2.Cells(NoLigZ2 + 1, 10).Value = WorksheetFunction.StDev(FLZ2.Range(Cells(1, 10), Cells(NoLigZ2, 10)))

    'variance
    FLZ2.Cells(NoLigZ2 + 2, 1).Value = "variance"
    FLZ2.Cells(NoLigZ2 + 2, 7).Value = WorksheetFunction.Var(FLZ2.Range(Cells(1, 7), Cells(NoLigZ2, 7)))
    FLZ2.Cells(NoLigZ2 + 2, 8).Value = WorksheetFunction.Var(FLZ2.Range(Cells(1, 7), Cells(NoLigZ2, 7)))
    FLZ2.Cells(NoLigZ2 + 2, 9).Value = WorksheetFunction.Var(FLZ2.Range(Cells(1, 7), Cells(NoLigZ2, 7)))
    FLZ2.Cells(NoLigZ2 + 2, 10).Value = WorksheetFunction.Var(FLZ2.Range(Cells(1, 10), Cells(NoLigZ2, 10)))

     'FeuilleZone3

    'Moyenne
    FLZ3.Cells(NoLigZ3, 1).Value = "Moyenne"
    FLZ3.Cells(NoLigZ3, 7).Value = WorksheetFunction.Average(FLZ3.Range(Cells(1, 7), Cells(NoLigZ3, 7)))
    FLZ3.Cells(NoLigZ3, 8).Value = WorksheetFunction.Average(FLZ3.Range(Cells(1, 8), Cells(NoLigZ3, 8)))
    FLZ3.Cells(NoLigZ3, 9).Value = WorksheetFunction.Average(FLZ3.Range(Cells(1, 9), Cells(NoLigZ3, 9)))
    FLZ3.Cells(NoLigZ3, 10).Value = WorksheetFunction.Average(FLZ3.Range(Cells(1, 10), Cells(NoLigZ3, 10)))

    'ecart-type
    FLZ3.Cells(NoLigZ3 + 1, 1).Value = "ecart-type"
    FLZ3.Cells(NoLigZ3 + 1, 7).Value = WorksheetFunction.StDev(FLZ3.Range(Cells(1, 7), Cells(NoLigZ3, 7)))
    FLZ3.Cells(NoLigZ3 + 1, 8).Value = WorksheetFunction.StDev(FLZ3.Range(Cells(1, 8), Cells(NoLigZ3, 8)))
    FLZ3.Cells(NoLigZ3 + 1, 9).Value = WorksheetFunction.StDev(FLZ3.Range(Cells(1, 9), Cells(NoLigZ3, 9)))
    FLZ3.Cells(NoLigZ3 + 1, 10).Value = WorksheetFunction.StDev(FLZ3.Range(Cells(1, 10), Cells(NoLigZ3, 10)))

    'variance
    FLZ3.Cells(NoLigZ3 + 2, 1).Value = "variance"
    FLZ3.Cells(NoLigZ3 + 2, 7).Value = WorksheetFunction.Var(FLZ3.Range(Cells(1, 7), Cells(NoLigZ3, 7)))
    FLZ3.Cells(NoLigZ3 + 2, 8).Value = WorksheetFunction.Var(FLZ3.Range(Cells(1, 7), Cells(NoLigZ3, 7)))
    FLZ3.Cells(NoLigZ3 + 2, 9).Value = WorksheetFunction.Var(FLZ3.Range(Cells(1, 7), Cells(NoLigZ3, 7)))
    FLZ3.Cells(NoLigZ3 + 2, 10).Value = WorksheetFunction.Var(FLZ3.Range(Cells(1, 10), Cells(NoLigZ3, 10)))

End Sub

l'erreur se presente sur la ligne

FLZ1.Cells(NoLigZ1, 7).Value = WorksheetFunction.Average(FLZ1.Range(Cells(1, 7), Cells(NoLigZ1, 7)))

si quelqu'un peut m'aider merci beaucoup

il manque le nom de la feuille devant tes cells en fin de formule

(FLZ1.Range(FLZ1.Cells(NoLigZ1, 7), FLZ1.Cells(NoLigZ1 + 100, 7)))

Merci beaucoup

Rechercher des sujets similaires à "calculer moyenne worksheetfunxtion"