+ Reply to Thread
Results 1 to 8 of 8

Average of the first X non blank cells

  1. #1
    Registered User
    Join Date
    04-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    Average of the first X non blank cells

    Say, I have a cell that has a number X (A1 = 5). Then I have an column B that has numbers, some of them are blanks. I need to calculate the average of the first X non blank numbers. How do I do that - Thanks in advance.

    Example :
    Cell A1 has 5.
    Column B has,
    1
    2
    Blank (actually blank, not the word)
    3
    Blank
    4
    5
    Blank
    Blank
    6
    7
    8

    Since the A1 has 5, I would only take the first 5 non blank values, (1, 2, blank, 3, blank, 4, blank, 5) and calculate the average as 15/ 5 = 3.

    Thank you!
    Last edited by agbagb0; 04-20-2013 at 11:57 AM.

  2. #2
    Valued Forum Contributor AZ-XL's Avatar
    Join Date
    03-22-2013
    Location
    Azerbaijan, Baku
    MS-Off Ver
    Excel 2007
    Posts
    603

    Re: Average of the first X non blank cells

    a1 cell equal 5 (you can change it)
    your numbers from b1 cell

    formula for answer

    =AVERAGEIF(OFFSET(B1,0,0,SMALL(IF(ISNUMBER(B1:B12),ROW(B1:B12),""),A1),1),"<>0") Ctrl+Shift+enter

    here is the file
    Attached Files Attached Files
    Appreciate the help? CLICK *

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Average of the first X non blank cells

    If you want the formula to work in Excel 2003 then perhaps just use AVERAGE, i.e.

    =AVERAGE(OFFSET(B1,0,0,SMALL(IF(ISNUMBER(B1:B12),ROW(B1:B12)),A1)))
    Audere est facere

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Average of the first X non blank cells

    Assuming there will always be X numbers to average.

    Array entered**:

    =AVERAGE(B1:INDEX(B1:B20,SMALL(IF(ISNUMBER(B1:B20),ROW(B1:B20)),A1)-ROW(B1)+1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    04-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up Re: Average of the first X non blank cells

    Quote Originally Posted by Tony Valko View Post
    Assuming there will always be X numbers to average.

    Array entered**:

    =AVERAGE(B1:INDEX(B1:B20,SMALL(IF(ISNUMBER(B1:B20),ROW(B1:B20)),A1)-ROW(B1)+1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    You guys are awesome.

    Thanks everyone - AZ-XL (solution in a file - great!) , daddylonglegs and Tony Valko! All the solutions have worked.

    Tony Valko - Thanks for the tip on how to enter array formulas ! I got an error and I was wondering how to fix it!

    Solved - how NOT to enter array formula - Post3206212.jpg

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Average of the first X non blank cells

    Good deal. Thanks for the feedback!

  7. #7
    Registered User
    Join Date
    01-06-2021
    Location
    Boston, Massachusetts, USA
    MS-Off Ver
    360
    Posts
    1

    Re: Average of the first X non blank cells

    What if There isnt X numbers to average? How would i get to average whatever it maxes at. So i want to average 12, 24, 48 and i some instances there isnt enough to fill that requirement, but i would still like it to average what ever number is available

    Thanks

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Average of the first X non blank cells

    Quote Originally Posted by Sconz1227 View Post
    What if There isnt X numbers to average? How would i get to average whatever it maxes at. So i want to average 12, 24, 48 and i some instances there isnt enough to fill that requirement, but i would still like it to average what ever number is available

    Thanks
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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