+ Reply to Thread
Results 1 to 4 of 4

Looking for a Wildcard Match Function

  1. #1
    Registered User
    Join Date
    12-08-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Looking for a Wildcard Match Function

    Hi guys,

    I'm looking for a function in VBA that returns TRUE if a given string matches a string with wildcards.

    e.g. WILDCARDMATCH("worldwideweb", "*orl*idewe*") returns TRUE

    Thanks a lot in advance!
    Siebe

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Looking for a Wildcard Match Function

    try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-08-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Looking for a Wildcard Match Function

    I'm not sure that that is accurate enough. I need a precise match, no errors allowed...

    But thanks for the suggestion.
    Siebe

  4. #4
    Registered User
    Join Date
    12-08-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Looking for a Wildcard Match Function

    If I can make others happy with it: here's the solution I ended up writing myself.

    Basic philosophy:
    1. Create a newString that has the same length as the string you're checking and that consists entirely of "*"'s
    2. Divide the mask string (delimited by the wildcards) into components and search inside your seach string if they're there.
    3. If a component from the mask actually appears to be part of your string, replace the same section in the 'newString' from step 1 with that component
    4. Finally replace all double or multiple **'s by single *'s.
    5. If the resulting 'new string' equals the mask string, you're successful!

    Example:
    1. Check JRRTolkien agains *RRTo*ie*
    2. Create a new string of the original length, containing only *'s: **********
    3. Split *RRTo**ie* by wildcard. This results in two strings: RRTo and ie
    4. If RRTo appears in your search string, replace the same sequence in the new string: ********** becomes *RRTo*****
    5. If ie appears in your string, replace the same sequence in the new string: *RRTo***** becomes *RRTo**ie*
    6. Replace all double appearances of * by single *. *RTo**ie* becomes *RTo*ie*
    7. The result ends up being equal to the original mask provided, so return TRUE.

    Note: the only thing I didn't provide is the function for parsing the mask.
    I assume however that alternatives are not too hard to create e.g. using the SPLIT-function.

    Please Login or Register  to view this content.
    Last edited by SiebeBosch; 12-08-2013 at 06:34 PM. Reason: minor corrections

+ 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] Wildcard text match using INDEX and MATCH
    By mmayna03 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-12-2012, 03:02 PM
  2. Replies: 4
    Last Post: 04-02-2012, 01:19 AM
  3. How to do a wildcard match in a match function
    By mike12345 in forum Excel General
    Replies: 1
    Last Post: 12-10-2011, 08:00 PM
  4. Excel 2007 : Wildcard match
    By localhost in forum Excel General
    Replies: 7
    Last Post: 05-31-2010, 01:44 PM
  5. Replies: 4
    Last Post: 12-14-2009, 03:21 PM

Tags for this Thread

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