Consulting

Results 1 to 4 of 4

Thread: Formula to calculate AVERAGE but only to last used row in a grid.

  1. #1
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location

    Formula to calculate AVERAGE but only to last used row in a grid.

    Good afternoon,

    I have a grid of cells C16:O25 where there are only values and empty cells, no formulas.
    I want to calculate the average for each column within the grid.
    I want it to calculate the average to include 0 for empty cells but only calculate the average down to the last used row from C:O.
    As you can see from the example, column C finishes in row 20, BUT the actual last row is 21.
    I would like it to go down to row 21 for all the calculations please.
    The last row in future might be 18 or 22 or 25 for example.

    The correct results are shown in cells C26:O26 but I obviously want them in cells C15:O15 please.

    I have tried using the formula...

    =AVERAGE(0+C16:C25)
    ...but this calculates it down to row 25, regardless if the last row was different.

    I have tried using INDEX/MATCH but without any luck.

    Any help will be appreciated.

    Thanks in advance.
    Attached Files Attached Files
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  2. #2
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Not to worry,

    I used a helper column from B16:B25 with the formulas:

    =IF(SUM(C16:O16)>0,1,"")
    =IF(SUM(C17:O17)>0,B16+1,"")
    ...etc down to cell B25.

    Then formulas:

    =IFERROR(SUM(C16:C25)/MAX($B16:$B25),0)
    ...copied across from cells C15:O15.

    Thanks to all those that looked though.

    EDIT: Formula change to include if there was no data that it would not invoke a #DIV/0! error.
    Last edited by PAB; 01-25-2017 at 08:55 AM. Reason: Formula Change.
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    in cell C15, array enter (Ctrl+Shift+Enter, not just Enter):
    =SUM(C$16:C$25)/(MAX(IF(LEN($C$16:$O$25)>0,ROW($C$16:$O$25)))-15)
    and copy across.

    Or
    =SUM(C$16:C$25)/(MAX(IF(ISNUMBER($C$16:$O$25),ROW($C$16:$O$25)))-15)
    if you want it to be insensitive to text in the grid.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Brilliant, thanks very much p45cal, it is appreciated.
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

Posting Permissions

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