Consulting

Results 1 to 3 of 3

Thread: Syntax on Application.Average

  1. #1

    Syntax on Application.Average

    This is a stupid question, but I am having a lot of trouble finding help on this one:

    I am trying to use the "Average" worksheet function. Due to the nature of my code, it is more convenient for me to refer to ranges using the 'Cells()' method.

    This works:
    [VBA]RowAverage = Application.Average(Cells(i + 3, 2), Cells(i + 3, 29))[/VBA]

    But this only returns the average of the 2 cells. I want the average of all cells in the RANGE Cells(i + 3, 2) To Cells(i + 3, 29)/

    I tried

    This
    [VBA]Application.Average(Cells(i + 3, 2) : Cells(i + 3, 29))[/VBA]

    This
    [VBA]Application.Average("Cells(i + 3, 2)" : "Cells(i + 3, 29)")[/VBA]

    Even this
    [VBA]Application.Average(Cells(i + 3, 2) To Cells(i + 3, 29))[/VBA]

    but all have syntax errors....Any thoughts?

  2. #2
    This is stupid. I just tried using the regular old Average syntax in VBA

    [VBA]Application.WorkSheetFunction.Average(A1:A20)[/VBA]

    and it gave me a syntax error. Apparently in VBA, Average() will only take arguments like this:

    [VBA]Application.WorkSheetFunction.Average(arg1, arg2, arg3)[/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Application.Average(Range(Cells(i + 3, 2), Cells(i + 3, 29)) )
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •