+ Reply to Thread
Results 1 to 8 of 8

find string pos from strings in an array

  1. #1
    Registered User
    Join Date
    09-11-2008
    Location
    Texas
    Posts
    7

    find string pos from strings in an array

    I am trying to find the string position of a string, and the string I am looking FOR is from an array of terms in another worksheet. I have it looking like this, but am getting a "type mismatch error" on this line...

    Please Login or Register  to view this content.

    Here is my entire code. Any help will be appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    InStr locates a substring within another string, not in an array.

    You might use the Match function.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-11-2008
    Location
    Texas
    Posts
    7
    Thanks, but match function won't work for my needs. I need to have the position so that I can use the mid function to make modifications.

    So to use inStr, I will need to loop through the array. Right?

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    That's what the match function does. Read shg's post again.

  5. #5
    Registered User
    Join Date
    09-11-2008
    Location
    Texas
    Posts
    7
    it looks like MATCH does just the opposite. It looks for a substring within an array. My array contains the substrings, and I need to find substring position within the string. Is there a way to do this?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    I don't know where you're looking. Why don't you attach a sample of what you're doing?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    So you are, sorry.

    You can do this with an array formula from the user interface, e.g.,

    {=MATCH(TRUE, ISNUMBER(SEARCH(B1:B3, A1)), 0)}

    ... but in VBA, I think you need to iterate through the array.
    Last edited by shg; 09-30-2008 at 12:16 PM.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello friscokid,

    This version of your macro takes advantage of the Range Objects properties and methods to eliminate the need for nested looping and a dynamic array. This code can be modified to find multiple occurances of the substring quite easily, if you need that feature later.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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. Find Specific string
    By janjan_376 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-30-2009, 12:38 PM
  2. Desire Versatile Alphanumeric Extractor From Any String
    By bxc2739 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-25-2007, 04:12 PM
  3. How to find and extract numbers that may be present in lengthy text strings
    By Langkawi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2007, 03:17 PM
  4. Replies: 2
    Last Post: 02-22-2007, 12:42 PM
  5. Replies: 7
    Last Post: 02-19-2007, 12:17 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