+ Reply to Thread
Results 1 to 8 of 8

Search backward in range till empty cell

  1. #1
    Registered User
    Join Date
    04-03-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    5

    Search backward in range till empty cell

    I manage a league and I have a large spreadsheet of scores for each player in the league. Each player has a row and every week I record their score in the next column in that row.

    What I want to do is find out the current "attendance" streak for each player in the league. In other words how many current weeks in a row has each player showed up since they last missed a week - could be zero, could be 30.

    So I need a routine/formula to loop through a range- backwards, and count the number of non-empty cells until it reaches an empty cell and then report the count. I assume this requires VBA but I could not figure out how to loop through a range (row) backwards looking for an empty cell.

    I've attached a sample spreadsheet
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Search backward in range till empty cell

    Hi,

    One of many possible solutions, I'm sure. This needs to be entered as an array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER). In cell EC9 and copy down as required:

    =MAX(COLUMN($C9:$DW9))-MAX(IF($C9:$DW9="",COLUMN($C9:$DW9)))

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    04-03-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search backward in range till empty cell

    WOW. Great answer! Many Thanks!

    If I understand this formula correctly, it looks for the count of the last empty cell then subtracts that from the count of all the cells. So there is no reason to loop backwards through the cells. Very nice!!

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Search backward in range till empty cell

    You're welcome!

  5. #5
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: Search backward in range till empty cell

    Note that this solution only finds the current streak, and not the player's maximum overall streak. Great answer though!

  6. #6
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: Search backward in range till empty cell

    Try "Non Array" formula

    EC9: =LOOKUP(1E+99,COLUMN(C9:DW9))-LOOKUP(2,1/(C9:DW9=""),COLUMN(C9:DW9))

    Normally Enter. Copy down as far as needed.

  7. #7
    Registered User
    Join Date
    04-03-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search backward in range till empty cell

    Thanks Teethless. Works perfectly.

    I can't seem to get my head around your solution. Can you provide a little explanation of how this works?

  8. #8
    Registered User
    Join Date
    04-03-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search backward in range till empty cell

    XOR,

    I love your formula - I want the last streak just as your formula gives.

    I was wondering if you could expand this just a bit. MY problem is that the range of data to apply your formula is in the middle of a giant worksheet and the last column I want to search changes each week.

    So I need to bound your formula (now bounded by $DW$9) with the last used column in a range within lots of other stuff. I assume I need the offset function and I've made some progress:

    I did figure out how to find the last used column within my range:

    =MAX(COLUMN($D$4:$AM$8)*($D$4:$AM$8<>""))-COLUMN($D$4)+1

    But I can't figure out how to apply this to your formula

    [Spreadsheet Attached]
    Attached Files Attached Files
    Last edited by fedude; 08-06-2013 at 08:03 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro code for copying formulas till the last non-empty cell
    By Zozika in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-28-2013, 08:47 AM
  2. Search for specific data and count number of rows till empty Cell
    By kjanani30 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2013, 06:05 AM
  3. [SOLVED] How to autofill any formula till last empty cell
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2013, 08:56 AM
  4. [SOLVED] Looping till empty cell
    By Alexander_Golinsky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2012, 02:11 PM
  5. Fill array till first empty cell.
    By UncleDucc in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-05-2009, 09:56 AM

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