+ Reply to Thread
Results 1 to 4 of 4

check if value is in array

  1. #1
    Registered User
    Join Date
    09-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    78

    check if value is in array

    I am using a function I found online called "IsInArray," which checks if a value is in an array and returns true of false. It doesn't seem to be working in this case. In the example below, I have a named range "names", and I have a sub which stores the range in an array and runs IsInArray for "BLUE WATER JEWELERS" in the array. This returns false even though the value is in the range.

    The workbook with the code: ExistsInArray.xlsm

    Here is the named range called "names":

    Account Name
    ALBERT S SMYTH CO, INC
    BILL FRENCH JEWELERS
    BLAND'S JEWELERS
    BLUE WATER JEWELERS
    BRAUNSCHWEIGER JEWELERS

    here is the VBA:

    Please Login or Register  to view this content.
    Last edited by bsapaka; 10-31-2014 at 04:06 AM.

  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
    45,012

    Re: check if value is in array

    I think that your test passes a two dimensional array to the function, albeit, the second dimension is 1. Using Transpose on a vertical range converts it to a one dimensional array ... which is what, I think, the function is expecting. Proof ... pudding

    Please Login or Register  to view this content.

    Regards, TMS
    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 Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: check if value is in array

    Loading a range from a worksheet to an array creates a 2 dimensional array - you're aware of this as you use a Message Box to show element (5,1)

    The JOIN() function cannot be used to join a multi-dimensional array...

    Your code modified to use a function by a 3rd party (http://excellerando.blogspot.co.uk/2...ons-for-2.html)

    Please Login or Register  to view this content.
    Quickly tested and seems to work - but you should stress it a little...

    (Offered as an example - I had other uses for the code recently)
    Last edited by cytop; 10-31-2014 at 05:38 AM.

  4. #4
    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
    45,012

    Re: check if value is in array

    A shorter version using COUNTIF without the complication of the dimensions of an array. The data can be column based, row based, or 2D range based.

    Please Login or Register  to view this content.

    You could probably easily adapt this to take a third parameter to determine if an exact match was required.


    Regards, TMS

+ 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. [SOLVED] Range to array, then check to see if the array contains a string
    By yeahyeahyeah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2012, 12:17 PM
  2. Check value in a array sum
    By johnny_martins00 in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 12-15-2011, 07:11 AM
  3. check a value in array
    By krish T in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-05-2010, 07:12 AM
  4. how to check the array have value
    By x taol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-01-2006, 06:00 AM
  5. [SOLVED] Array Check
    By NacellesEng in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-28-2005, 04: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