+ Reply to Thread
Results 1 to 6 of 6

Search array for a value, returns index location

  1. #1
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Red face Search array for a value, returns index location

    Hello Excelforum!

    I am trying to write a function that searches an array for a value and returns the index(es) of where the value is found.

    Say I have an array, arrAccNos() with elements (1, 2, 3, Something, 1) and I want to find out if the array contains the value 1 as well as where the value 1 was found in the array. The function should operate like this:

    FindInArray(arrAccNos, 1) would return "1,5" as a string. (no quotes)
    FindInArray(arrAccNos, something) would return "4" as a string. (no quotes)
    FindInArray(arrAccNos, SoMeTHinG) would return "4" as a string. (no quotes)
    FindInArray(arrAccNos, somethingelse) would return "errNotFound" as a string. (no quotes)

    Thank you for your help!

  2. #2
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Search array for a value, returns index location

    I don't know why I said to have the returns as strings. I suppose having it return longs for all but errNotFound would work better.

    Probably easier to have everything return as long and instead of errNotFound have it return 0 or "" or something. Anything would work. Specifics were given to describe how I intend to use it. Thank you.
    Last edited by smpita; 06-24-2014 at 04:04 PM.

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Search array for a value, returns index location

    See how next code can help
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Search array for a value, returns index location

    Works great! Thank you, PCI!

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Search array for a value, returns index location

    Something similar.. only difference is it uses StrComp function..

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Search array for a value, returns index location

    Thank you apo. I have changed my code to use the StrComp function as it looks like it will be a useful function for future use in other applications.

+ 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. Array/Index/Match/small formulas- creating a quick search
    By lreed in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-25-2014, 06:06 PM
  2. SEARCH function returns array if first argument is array--Huh?
    By 6StringJazzer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-10-2012, 07:23 PM
  3. [SOLVED] Using Index and Match to search an array that has multiple items in each cell
    By tdlewis in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-20-2012, 08:45 PM
  4. Help Needed in Using Index Array w/2 Search Criteria in Excel
    By Cliff.Sizemore in forum Excel General
    Replies: 5
    Last Post: 03-05-2012, 09:14 PM
  5. [SOLVED] Looking for formula index/match-type that returns an array
    By Tom in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-01-2005, 05:06 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