+ Reply to Thread
Results 1 to 7 of 7

Find function - use with an array

  1. #1
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Find function - use with an array

    Hello forum,

    I am trying to use the Find formula to test if a particular value matches one of the elements in a named array.

    I have created the array in the Name Manager: "SheetLetters" = {"SU","TR","SX"}.

    If I put this formula in a cell, =FIND("SU",SheetLetters,1), it returns 1.
    but if I use this formula, FIND("SX",SheetLetters,1), it returns #VALUE!

    What I would like is for a number to be returned if the search string matches any of the values stored in the array. Any advice would be much appreciated as always.

    thanks

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find function - use with an array

    Try this:
    Please Login or Register  to view this content.

    or...for a case-insensitive search:
    Please Login or Register  to view this content.

    Edited to include the below:
    If there are no matches...this formula traps the error:
    Please Login or Register  to view this content.

    Also...(there seems to be many approaches to this)
    Please Login or Register  to view this content.


    Does that help?
    Last edited by Ron Coderre; 04-10-2011 at 08:31 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Find function - use with an array

    Thanks Ron, that works a treat.
    I'd like to understand how and why it works though! If you have time to drop me a few lines of explanation that would be great.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find function - use with an array

    Which "that" are your referring to?

  5. #5
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Find function - use with an array

    Sorry Ron - I'm not being very helpful in helping you to help me.
    I meant this one:

    =LOOKUP(10^99,SEARCH("sX",SheetLetters))

    thanks again.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find function - use with an array

    Here's how this formula works:
    =LOOKUP(10^99,SEARCH("sX",SheetLetters))

    You already know that the SEARCH function returns a number (for matched items) or an error (for non-matched items)

    Two of the useful features (bugs?) of the LOOKUP function are:
    • if the item to be found is larger than any of the list values
    ---it returns the last list value of the same type as the item (numeric, in this case)
    • it ignores errors

    So, in the above formula, we are looking for an extremely large number: 10^99
    in a list that will consist of either a number and two errors, like {#VALUE!,1,#VALUE!}
    or three errors {#VALUE!,#VALUE!,#VALUE!}

    If any of the tests results in a match, the numeric value will be returned.
    Otherwise, there will be no numeric values and the LOOKUP function will return an error.

    I hope that helps.

  7. #7
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Find function - use with an array

    Thanks for that explanation. Yes that's a great help - I prefer to be able to follow what's happening, rather than just copy some code and move on!

+ 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