+ Reply to Thread
Results 1 to 14 of 14

Find the first number after the last zero in a column

  1. #1
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Find the first number after the last zero in a column

    I would appreciate any and all help on the following:

    I have three columns:
    Column B has dates from 1/1 to 12/31.
    Column C has weekdays from Column B.
    Column D has both numbers and blank cells from formulas referencing another sheet.

    Column D is sectioned off weekly, meaning that every Sunday is a blank cell.
    Column D has zeroes to the last date of the year.

    Here’s an example:

    B C D
    7/10 Fri 5
    7/11 Sat 10
    7/12 Sun
    7/13 Mon 5
    7/14 Tue 6
    7/15 Wed 8
    7/16 Thu 6
    7/17 Fri 0
    7/18 Sat 10
    7/19 Sun
    7/20 Mon 5

    I would like to find the first number greater than zero immediately after the last zero in Column D not counting the last cell in the column, and return the corresponding date from Column B.

    I am not looking for the last zero, which would correspond to 12/31.

    So for the above example, I would like to have 7/18 as the answer.

    Thanks all.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Find the first number after the last zero in a column

    One way, with a Helper column ...


    A
    B
    C
    D
    E
    F
    G
    1
    Help
    7/28
    =INDEX(A:A,MATCH(MAX(D:D),D:D,0)+1)
    2
    7/10
    Fri
    5
    0
    =IF(AND(C2<>"",C2=0),MAX($D$1:D1)+1,0)
    3
    7/11
    Sat
    10
    0
    4
    7/12
    Sun
    0
    5
    7/13
    Mon
    5
    0
    6
    7/14
    Tue
    6
    0
    7
    7/15
    Wed
    8
    0
    8
    7/16
    Thu
    6
    0
    9
    7/17
    Fri
    0
    1
    10
    7/18
    Sat
    10
    0
    11
    7/19
    Sun
    0
    12
    7/20
    Mon
    5
    0
    13
    7/10
    Fri
    5
    0
    14
    7/11
    Sat
    10
    0
    15
    7/12
    Sun
    0
    16
    7/13
    Mon
    5
    0
    17
    7/14
    Tue
    6
    0
    18
    7/15
    Wed
    8
    0
    19
    7/16
    Thu
    6
    0
    20
    7/17
    Fri
    0
    2
    21
    7/28
    Sat
    10
    0
    22
    7/19
    Sun
    0
    23
    7/20
    Mon
    5
    0




    Regards, TMS
    Last edited by TMS; 07-30-2015 at 12:46 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,906

    Re: Find the first number after the last zero in a column

    Try this VBA solution

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Re: Find the first number after the last zero in a column

    Alan,
    Thank you for your help, but I'm trying to stay away from macros.

    TMS,
    Thank you also. The first helper column is wonderful. Although sadly, 7/17 is the 5th occurrence of a zero.

    Because I have a formula in each cell in Column D (your Column C), excluding Sundays, I have a bunch of zeroes through the rest of the column. This makes your INDEX/MATCH formula unworkable.

    If it would help to insert my Excel sheet let me know, and I'll do that.

    Thanks again.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,906

    Re: Find the first number after the last zero in a column

    Alan,
    Thank you for your help, but I'm trying to stay away from macros.
    Any particular reason for this action to avoid VBA? Always curious to understand what motivates this type of avoidance.

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Find the first number after the last zero in a column

    Try

    =LOOKUP(2,1/((D1:D10=0)*(D1:D10<>"")),B2:B11)

    Notice the 1 row offset between the two ranges D1:D10 and B2:B11

  7. #7
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Re: Find the first number after the last zero in a column

    Quote Originally Posted by alansidman View Post
    Any particular reason for this action to avoid VBA? Always curious to understand what motivates this type of avoidance.
    In my tiny, little mind VBA is long and complex, with a lot of room for error. The reality might be very different, but I have had a hard time getting my head around the language.

  8. #8
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Re: Find the first number after the last zero in a column

    I've attached an example worksheet. In it I have the 3 pertinent columns of data, and their placement on the worksheet.

    I hope this helps you guys.
    Attached Files Attached Files

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Find the first number after the last zero in a column

    Did you try the formula I suggested?

    What is your expected result in that book you posted?

  10. #10
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Re: Find the first number after the last zero in a column

    Quote Originally Posted by Jonmo1 View Post
    Did you try the formula I suggested?

    What is your expected result in that book you posted?
    Yes I did, and I got a 0, which is why I posted the excel sheet. I couldn't get it to work within the columns and rows I have set up.

    The result I'm looking for from that sheet would be the date of 7/29.

    Thanks.

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Find the first number after the last zero in a column

    Try this one, again, notice the 1 row offsets between the ranges.

    =LOOKUP(2,1/((D3:D369=0)*(D3:D369<>"")*(D4:D370>0)),B4:B370)

  12. #12
    Registered User
    Join Date
    07-29-2015
    Location
    FLA
    MS-Off Ver
    2007
    Posts
    8

    Re: Find the first number after the last zero in a column

    Oh Jonmo1: You Rock!

    It works perfectly!

    Adding to your Rep. Changing Topic to SOLVED. And hoping I don't have any more zeroes for the rest of the year.

  13. #13
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Find the first number after the last zero in a column

    You're welcome.

  14. #14
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,906

    Re: Find the first number after the last zero in a column

    FYI:

    Thanks for your response on VBA. As a point of interest, here is how to install. Once installed, if you step through the code, F8 on the debug menu, will help you understand what is happening.

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

+ 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. Replies: 5
    Last Post: 02-13-2014, 05:37 PM
  2. Find number in row and display number and column title
    By johan87 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-23-2013, 08:30 AM
  3. Replies: 1
    Last Post: 06-10-2013, 07:08 PM
  4. Find highest revision number in one column of a item number in another column
    By Tasiast in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2013, 01:03 PM
  5. Replies: 4
    Last Post: 11-13-2012, 02:16 PM
  6. [SOLVED] find number of times a letter or a number appears in a column
    By dcoates in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-17-2012, 02:47 PM
  7. Replies: 7
    Last Post: 12-18-2008, 07:34 PM

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