+ Reply to Thread
Results 1 to 6 of 6

Does current Array Element Contain Text from Another Array?

  1. #1
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 2016
    Posts
    260

    Does current Array Element Contain Text from Another Array?

    This is driving me nuts...

    I have two arrays. The first one is a 1D string array containing a Master List of possible defects, which is dynamically sized and filled based on a series of TRUE/FALSE entries by the user. I have VBA code that runs properly to create and populate this array, so typically it would look something like:

    arrLeadMeasures(Mechanical, Electrical, Other)

    The next array is a list of actual failures and is a 2D variant array called arrFailureModes that is also dynamically populated. Again this part of the VBA works okay. The array FailureModes typically looks something like:

    Pump, Electrical, AirIntake, Other
    Electrical, Electrical, Other, Tyres
    etc etc


    The part I am having problems with is I need to iterate through arrFailureModes and for each element I need to check if the current entry is contained anywhere within arrLeadMeasures. So far I have a shell of code which is:

    Please Login or Register  to view this content.
    I think I could take the current element of arrFailureModes and iterate through every element of arrLeadMeasures and use something like InStr to see if there is a match, but I think there must be a more elegant solution using something like IsInArray, perhaps? I've tried using the IsInArray syntax though and can't get it to work. In fact I can't get VBA to recognise IsInArray as a valid function to start with so getting nowhere with it!

    Been pulling my hair out for over an hour now so thought it best to ask for some advice before I'm bald! :-)
    Last edited by TheRobsterUK; 10-17-2018 at 10:50 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Does current Array Element Contain Text from Another Array?

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Does current Array Element Contain Text from Another Array?

    Something like
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Does current Array Element Contain Text from Another Array?

    Similar to Fluff's...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 2016
    Posts
    260

    Re: Does current Array Element Contain Text from Another Array?

    That's great guys, thanks for the help. It didn't quite work so had to change it to:

    Please Login or Register  to view this content.
    For some reason it doesn't like it when the current element of the array is entered into the IsInArray function as arrFailureModes(i, j) but when this is passed to a string variable first and then the variable is used in the IsInArray function it the accepts it.

    Cheers!

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Does current Array Element Contain Text from Another Array?

    Please Login or Register  to view this content.

+ 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. Replies: 7
    Last Post: 03-23-2015, 03:36 PM
  2. Replies: 12
    Last Post: 01-14-2014, 01:56 PM
  3. Get nth element of array
    By Bob1980 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-06-2013, 12:50 PM
  4. [SOLVED] Read last element of Split array and then discard it and resize the array.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 06:36 PM
  5. [SOLVED] Returning an array specific to an element of a separate array
    By peterszabla in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-24-2012, 05:30 PM
  6. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  7. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 AM

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