+ Reply to Thread
Results 1 to 14 of 14

Find first value that meets some criteria

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Find first value that meets some criteria

    Is there a worksheet function that will return the index (or offset) of the first value in an array (row or column) that meets some criteria?

    For example, suppose I have the following values in C5:Q5:
    C D E F G H I J K L M N O P Q
    1 1 1 1 2 1 1 3 1 1 1 1 1 1 2

    I would like a formula that would give me the index (offset) of the first cell that contains a value other than "1" (<>1). In this case, that would be "5". The first value that is not a "1" is in G5, which is the 5th cell from C5.

    The Match function almost works, but it requires the values to be in order (ascending or descending).

    PS: I actually want it for a column of data, but a row was more compact to display.

  2. #2
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Find first value that meets some criteria

    It only needs to be in order if you allow approximate matcges. Exact matches can be in any order.
    Want to show appreciation for the help you received from a member? Give them reps by clicking the bottom left of their post!

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,388

    Re: Find first value that meets some criteria

    Hi Cynthia,

    Will you accept a helper column in your answer? See the attached that has a helper column.
    If you can't use a helper then you are going to need to learn Array Formulas.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: Find first value that meets some criteria

    Quote Originally Posted by Obsessed View Post
    It only needs to be in order if you allow approximate matches. Exact matches can be in any order.
    Not sure what you mean by "approximate". The problem as stated was a "not equal" match.

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

    Re: Find first value that meets some criteria

    Try this array formula**:

    =MATCH(TRUE,C5:Q5<>1,0)

    ** 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.

  6. #6
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: Find first value that meets some criteria

    Quote Originally Posted by MarvinP View Post
    Hi Cynthia,

    Will you accept a helper column in your answer? See the attached that has a helper column.
    Thanks for that example. It works, if I adjust to get the offset.

    If you can't use a helper then you are going to need to learn Array Formulas.
    I can, but I'd prefer a cleaner, more elegant solution. The Match function is so close. It has an "equal" option, a "less than or equal" option, and a "greater than or equal" option. Why didn't the geniuses at M$FT include a "not equal" option?

    OK, I've been meaning to learn array formulas. Care to get me started for this problem?

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

    Re: Find first value that meets some criteria

    Quote Originally Posted by Cynthia Moore View Post
    OK, I've been meaning to learn array formulas. Care to get me started for this problem?
    Sure, see post #5.

  8. #8
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: Find first value that meets some criteria

    Quote Originally Posted by Tony Valko View Post
    Try this array formula:

    =MATCH(TRUE,C5:Q5<>1,0)
    That works perfectly. I'll go figure out how.

    Thanks so much.

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

    Re: Find first value that meets some criteria

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

  10. #10
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: Find first value that meets some criteria

    Quote Originally Posted by Tony Valko View Post
    You're welcome. Thanks for the feedback!

    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.
    Tony,

    I marked the thread solved, but then I decided to take a crack at understanding array formulas.

    I marked it unsolved again and attached a little tutorial I wrote about this solution. If you have time, please check it out and let me know if there are any errors or misstatements.

    Thanks, C
    Attached Files Attached Files

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

    Re: Find first value that meets some criteria

    Sorry, I have download size limits so I'm not able to download your file.

  12. #12
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: Find first value that meets some criteria

    Quote Originally Posted by Tony Valko View Post
    Sorry, I have download size limits so I'm not able to download your file.
    Huh? It's only 329 KB!

    Here's the Word file. It's only 51 KB.
    Attached Files Attached Files

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

    Re: Find first value that meets some criteria

    OK, I was able to download the Word file.

    WRT there not being an entry that meets the logical test (range<>1)...

    By design, the MATCH function will return the #N/A error.

    Depending upon the application, you may want this result as it let's you know there are no matching entries.

    However, you may not want this result but you can use error trapping to prevent the #N/A result. There are different ways to do that depending upon what version of Excel you're using.

  14. #14
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find first value that meets some criteria

    An addition to Tony's formula if you are interested. You can get the address of the cell that holds the value returned by Tony's formula with this array formula.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Enter with Ctrl + shift + enter

    The 5 is the row that the value is to be found in. The MATCH(TRUE....is Tony's formula. The +2 is the offset of the range from column A. Finally, the 4 means a relative reference.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

+ 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. Need to find info in sreadsheet that meets two criteria - help please!
    By Altna in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2013, 07:11 AM
  2. [SOLVED] need to find MAX value IF meets criteria
    By rossg in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-03-2013, 10:58 PM
  3. [SOLVED] find last value in a column if it meets a certain criteria
    By chiidzzz in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-15-2012, 02:19 PM
  4. Find the last in a list that meets the certain criteria
    By csmall86 in forum Excel General
    Replies: 1
    Last Post: 10-31-2010, 12:27 PM
  5. Find cell that meets criteria
    By dudedude in forum Excel General
    Replies: 5
    Last Post: 07-08-2010, 08:31 AM
  6. How do I find the last row which meets criteria??
    By colwyn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2009, 12:34 PM
  7. [SOLVED] How can I find last row and score which meets criteria?
    By colwyn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2009, 07:24 AM
  8. In an array, I need to find the row # that meets 2 criteria
    By Space Elf in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-08-2006, 12:00 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