+ Reply to Thread
Results 1 to 3 of 3

.Find method does not find strings if the # of spaces do not match. Do I need a RegExp?

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    .Find method does not find strings if the # of spaces do not match. Do I need a RegExp?

    I recently helped a forum user on here and ended up trimming leading and trailing spaces with tedious code like what I posted below but I just know there is a better way.

    I was using the Find Method with arguments: RNG_AllNames_dest.Find(ValueToFind, After:=WS_dest.Range("A" & LRW_src), LookAt:=xlWhole, MatchCase:=False), with LRW_src as the last row in the range I'm searching.

    In order to avoid something like the code below, do I need to use a Regular Expression or is there an argument in the Find method that will ignore trailing and leading spaces in a string I'm searching?
    Please Login or Register  to view this content.
    <---If my answer helped, please click *

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: .Find method does not find strings if the # of spaces do not match. Do I need a RegExp

    If lookup values are unique except the leading or trailing spaces, try changing LookAt:=xlWhole to LookAt:=xlPart and see if that works. Or you may use something like What:=Trim(ValueToFind).
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

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

    Re: .Find method does not find strings if the # of spaces do not match. Do I need a RegExp

    Joe,
    Even with regular expression, the issue with be still there. You need to clean up the data using a trim function if it is space issue, or use replace and substitute functions to replace non space characters.
    Like
    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. Range.Find function fails to find a match but For loop confirms that match exists
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2013, 03:35 PM
  2. [SOLVED] Error when using FIND Method to find last row when column is blank
    By the duke in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-01-2013, 10:26 PM
  3. find method fails to find custom format date
    By yot68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2012, 06:28 PM
  4. Find method with 2 criteria match
    By zekethewolf in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2011, 11:08 AM
  5. Excel Find and . Find Method Question
    By cldcp00 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2010, 07:34 AM
  6. Find exact match in cell with multiple strings
    By Garage23 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-16-2010, 07:23 AM
  7. Using Find Method to match dates
    By Astroboy142 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2009, 05:17 AM
  8. [SOLVED] Using variables to make a date and using find method to find that.
    By KyWilde in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2005, 05: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