+ Reply to Thread
Results 1 to 14 of 14

Find the first value in a row greater than zero

  1. #1
    Registered User
    Join Date
    11-17-2008
    Location
    Adelaide,Australia
    Posts
    12

    Find the first value in a row greater than zero

    Hi,
    I'm trying to find the column number of the first cell in a row that is greater than zero.

    There are 31 columns of of data, so if statments aren't working for me.

    any suggestions

    Example
    1 2 3 4 5 6 7 8 9
    A 0 0 0 0 0 0 8 1 0 = 7
    B 0 0 2 0 0 0 0 0 0 = 3
    C 0 0 0 0 0 0 0 0 1 = 9

    Thanks

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find the first value in a row greater than zero

    You could use an Array

    AF1: =MATCH(TRUE,$A1:$AE1>0,0)
    confirmed with CTRL + SHIFT + ENTER

    copy down as required

    EDIT: I spotted from a daddlylonglegs post a way to use INDEX within the MATCH and thereby avoid need for Array...

    AF1: =MATCH(TRUE,INDEX($A1:$AE1>0,0),0)
    Last edited by DonkeyOte; 04-09-2009 at 03:35 AM. Reason: typo & dll edit

  3. #3
    Registered User
    Join Date
    06-13-2012
    Location
    Hamsterdam
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find the first value in a row greater than zero

    Quote Originally Posted by DonkeyOte View Post
    You could use an Array
    AF1: =MATCH(TRUE,INDEX($A1:$AE1>0,0),0)
    This is glorious, I use it all the time, thank you!

  4. #4
    Registered User
    Join Date
    06-15-2012
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Find the first value in a row greater than zero

    Fantastic! That is very useful!

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    poznań
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Find the first value in a row greater than zero

    Quote Originally Posted by DonkeyOte View Post
    You could use an Array

    AF1: =MATCH(TRUE,$A1:$AE1>0,0)
    confirmed with CTRL + SHIFT + ENTER

    copy down as required

    EDIT: I spotted from a daddlylonglegs post a way to use INDEX within the MATCH and thereby avoid need for Array...

    AF1: =MATCH(TRUE,INDEX($A1:$AE1>0,0),0)
    Thanks a lot for saving my ***!

  6. #6
    Registered User
    Join Date
    01-25-2010
    Location
    Joinville, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Find the first value in a row greater than zero

    Quote Originally Posted by DonkeyOte View Post
    AF1: =MATCH(TRUE,INDEX($A1:$AE1>0,0),0)
    Could someone explain to me why this works?

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Find the first value in a row greater than zero

    Quote Originally Posted by FortuneSyn View Post
    Could someone explain to me why this works?
    OK. Lets take a small example to show you how this works. Say the formula is MATCH(TRUE,INDEX($A1:$E1>0,0),0). And assuming that you have values 0 0 0 8 7 in the range A1:E1.

    First of all the INDEX($A1:$E1>0,0) gets executed. It will return the array of True and False as you are using 0 as row number so instead of returning a single value it will return the whole array like this.....
    {FALSE,FALSE,FALSE,TRUE,TRUE}

    So your formula Match formula becomes
    =MATCH(TRUE,{FALSE,FALSE,FALSE,TRUE,TRUE},0)

    Now in the Match function, the lookup value is TRUE and lookup array is {FALSE,FALSE,FALSE,TRUE,TRUE} and 0 is for exact match. So the Match will return the position of first TRUE in the array {FALSE,FALSE,FALSE,TRUE,TRUE} which is 4.
    Therefore the formula will return 4 since this is the position of first value which is greater than 0 in the range A1:A1.

    I hope this helps.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  8. #8
    Registered User
    Join Date
    09-03-2016
    Location
    India
    MS-Off Ver
    2007
    Posts
    4

    Re: Find the first value in a row greater than zero

    Dear All
    this is really useful & amazing
    Regards,
    Chirag

  9. #9
    Registered User
    Join Date
    01-16-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    2016
    Posts
    51

    Re: Find the first value in a row greater than zero

    This is awesome - thanks all!

  10. #10
    Registered User
    Join Date
    09-10-2014
    Location
    london
    MS-Off Ver
    office 2010
    Posts
    2

    Re: Find the first value in a row greater than zero

    Lets say then the values continue to be positive and then 0 again.
    How i can find the position of this second occurence?

    Example
    1 2 3 4 5 6 7 8 9
    A 0 0 0 0 0 0 8 1 0 = 9

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

    Re: Find the first value in a row greater than zero

    @PAP069

    Can you clarify with a few more examples, together with expected results?

    Regards
    Click * below if this answer helped

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

  12. #12
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,445

    Re: Find the first value in a row greater than zero

    Administrative Note:

    At PAP . since you have already created a new thread, there is no need to continue this one
    https://www.excelforum.com/excel-for...ive-value.html
    Last edited by Pepe Le Mokko; 06-21-2019 at 06:29 AM.

  13. #13
    Registered User
    Join Date
    01-16-2020
    Location
    Sweden
    MS-Off Ver
    No Idea
    Posts
    1

    Re: Find the first value in a row greater than zero

    SKTNeer

    I literally made an account just to thank you for your explanation. I've been spending the last 2 hours banging my head against a wall with some excel stuff and your explanation helped greatly.

    Thank you so ******* much.

  14. #14
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Find the first value in a row greater than zero

    Quote Originally Posted by Ceasefire3 View Post
    SKTNeer

    I literally made an account just to thank you for your explanation. I've been spending the last 2 hours banging my head against a wall with some excel stuff and your explanation helped greatly.

    Thank you so ******* much.
    Welcome to the forum!
    Glad you found it helpful.

+ 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