+ Reply to Thread
Results 1 to 14 of 14

Instr to look for a complete, exact match of a string

  1. #1
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Instr to look for a complete, exact match of a string

    Using the Instr function to append items to a string to create a list, I've encountered a problem where instr will not add the name of a new item to the list if the name of the new item contains part of the name of an item already in the list.

    For example, the list string contains the following values:

    "Advanced Microprocessor|Supercomputer|Computer|Keyboard|Logic Circuit"

    As the Instr continues its search for items to append to the list, it encounters "Microprocessor", but rejects it because it reads "Microprocessor" in "Advanced Microprocesser". It does the same for "Circuit" because it reads "Circuit" in "Logic Circuit"

    How can I get Instr to read the entire string of characters between the "|" as the basis for comparison. Doing so would make it recognize that these are distinct items and should be added to the list.

    Thanks in advance!


    EDIT: Here is the code in question.

    Please Login or Register  to view this content.
    Last edited by SandPounder1; 04-30-2014 at 01:53 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Instr to look for a complete, exact match of a string

    Convert in to case insensitive

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Instr to look for a complete, exact match of a string

    Should be

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Instr to look for a complete, exact match of a string

    Done. But it still does not add "Microprocessor" if "Advanced Microprocessor" is already in the list.

    Also, I typed "microprocessor" above mistakenly (now corrected), there is no difference in case in the list.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Instr to look for a complete, exact match of a string

    Yes, it would take in duplicates.

  6. #6
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Instr to look for a complete, exact match of a string

    I added a messagebox to show me the values instr is comparing (See below) and it looks like you are correct. However, the items are still not appearing in the list (So there is "Advanced Microprocessor", but not "Microprocessor" and "Logic Circuit", but not "Circuit").

    It must be a problem with how the data is being written to the string list.


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Instr to look for a complete, exact match of a string

    Well, that's not the case either. Let me share the real values being entered.

    Running through the code below, the first item is "Construction Materials", which gets added to the list. The second item that meets the criteria is "Advanced Electronic Construction Materials", which also gets added to the list. The third item is "Electronic Construction Materials", which does NOT get added to the list. The fourth item is "Tools", which does get added, and so on.

    Not sure why it skips "Electronic Construction Materials". Any ideas?





    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: Instr to look for a complete, exact match of a string

    If you could put the delimiter "|" on either side of the string search then you would be able to get exact matches. You would have to modify the code so your string looked like:

    "|Advanced Microprocessor|Supercomputer|Computer|Keyboard|Logic Circuit|"

    When the string is finished you could remove the leading and trailing delimiters with the mid function, i.e.
    Please Login or Register  to view this content.
    Regards,

    Tom

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Instr to look for a complete, exact match of a string

    I left out "NOT"

    Yes, it NOT would take in duplicates.

  10. #10
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: Instr to look for a complete, exact match of a string

    Running through the code below, the first item is "Construction Materials", which gets added to the list. The second item that meets the criteria is "Advanced Electronic Construction Materials", which also gets added to the list. The third item is "Electronic Construction Materials", which does NOT get added to the list. The fourth item is "Tools", which does get added, and so on.

    Not sure why it skips "Electronic Construction Materials". Any ideas?

    Yes, on the second test "Advanced Electronic Construction Materials" is not in the string, but on the third test "Electronic Construction Materials" is in the string (as part of "Advanced Electronic Construction Materials" )

    Regards,

    Tom

  11. #11
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Instr to look for a complete, exact match of a string

    I have added a | at the beginnng of the list, but still not getting the needed results.

    Regarding the question above, on the second test "Construction Materials" is also already in the list, but "Advanced Electronic Construction Materials" is added. Why will it not then add "Electronic Construction Matierials" as well, since both contain elements of an earlier entry?

    Starting to tear hair out ha-ha

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

    Re: Instr to look for a complete, exact match of a string

    Hello SandPounder1,

    InStr will search for the first occurrence of substring within the string to be search. It does not differentiate between a single words and phrases. To parse string data in this fashion you should use Regular Expressions.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  13. #13
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: Instr to look for a complete, exact match of a string

    Without code or a workbook to look at I'm not sure what you did. And I can't think of another way to explain what is happening but it is perfectly logical to me. Regardless this should meet your requirement (untested due to no workbook).

    Please Login or Register  to view this content.
    Regards,

    Tom

  14. #14
    Registered User
    Join Date
    02-06-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Instr to look for a complete, exact match of a string

    Worked like a charm!! Thanks again.

+ 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] Possible to search for a substring withing a string of text which is an exact match?
    By Urugmo88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-07-2014, 04:09 AM
  2. [SOLVED] Find Exact Match Text String Using Formula
    By sweetrevelation in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-12-2012, 10:53 AM
  3. [SOLVED] Count if - not exact match - from cell not string
    By s_twigge in forum Excel General
    Replies: 2
    Last Post: 06-27-2012, 10:44 AM
  4. Instr Function - Replace String 2 with Variables?
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-08-2010, 03:14 PM
  5. Defining string using InStr function help
    By Iwant2learn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2006, 12:29 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