+ Reply to Thread
Results 1 to 8 of 8

calculate average from an array with controlled length

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    Borlänge, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    3

    calculate average from an array with controlled length

    Hi,

    My problem:

    =AVERAGE(H2:H25)

    I want the row number for cell H25 to be controlled by a number from another cell. Lets say that the cell "A1" contains the value499, then I want the average calculation to be =AVERAGE(H2:H499). There is probably an easy way to solve this, but my excel-knowledge is not that good.

    Thanks in advance!

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,003

    Re: calculate average from an array with controlled length

    Here, try this:

    =AVERAGE(OFFSET(H2;0;0;A1))

    (replace ; with , if needed)
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    Borlänge, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: calculate average from an array with controlled length

    Thank you zbor!!!

    It works!

    Thanks for the incredible fast reply!

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: calculate average from an array with controlled length

    @ zbor
    Should it not be?
    Please Login or Register  to view this content.
    [EDIT]
    A non-volatile solution might be
    Please Login or Register  to view this content.
    Last edited by Marcol; 02-07-2012 at 05:53 AM.

  5. #5
    Registered User
    Join Date
    02-07-2012
    Location
    Borlänge, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: calculate average from an array with controlled length

    Yes, I realized that, but I did not want to bother with an "unnessicary" question!
    Thanks

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,003

    Re: calculate average from an array with controlled length

    If you put 1 in A1 it will take one cell. If you have A1-1 you will get #REF! error.

    But I agree, =AVERAGE(H2:INDEX(H:H,A1,1)) is better way.

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,640

    Re: calculate average from an array with controlled length

    How about
    =AVERAGE(INDIRECT("H2:H"&A1))
    Quang PT

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,003

    Re: calculate average from an array with controlled length

    It will work too, but still above solution is better because INDIRECT is alo a Volatile function.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1