+ Reply to Thread
Results 1 to 6 of 6

Bulk Find and Replace Whole Words, Not Strings

  1. #1
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Bulk Find and Replace Whole Words, Not Strings

    I have an Excel spreadsheet that contains a macro.

    Bulk Find Replace.xlsm

    Column A contains a list of phrases.
    Column F contains a list of values to FIND.
    Column G contains a list of values to REPLACE.

    What I want to achieve using VBA is a find/replace on WHOLE WORDS within column A by FINDING the value in column F and REPLACING with the value in column G.

    Using VBA, I want to append " " to the beginning and ending of each phrase in column A.

    For example, the phrase 'ediscovery institute havasu' would be seen as " "&ediscovery institute havasu&" ".

    Then, all the words in column F would also have " " appended to the beginning and end.

    This way, when the find/replace is performed, it will look for WHOLE WORDS instead of strings and replace those whole words found with the value in column G.

    Lastly, I'd like to then trim the results in column A using VBA then end macro.

    I know how to do this with a formula but I don't know how to do this with VBA.

    This is the code in the current workbook:
    Please Login or Register  to view this content.
    Last edited by sweetrevelation; 04-05-2013 at 02:29 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Bulk Find and Replace Whole Words, Not Strings

    Is this how you wanted?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Bulk Find and Replace Whole Words, Not Strings

    Thanks Jindon. Your solution works almost as expected for me. Thanks so much.

    I put together a scenario to explain the scenario that produces undesired results:

    Bulk Find Replace Replace Value.xlsm

    In this example, I want to find the whole word 'mo' and replace it with the value in column G 'month' after clicking the "Push Me!" button.

    When I do though, it replaces 'mo' with 'month' but mashes the words month and old to create 'monthold'.

    The desired end-result is 'month old'

    What part of your code could I modify to achieve this?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Bulk Find and Replace Whole Words, Not Strings

    Can you change to
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Bulk Find and Replace Whole Words, Not Strings

    That resolved it Jindon! Thank you so much for all your help. Rep added. Thread resolved. I'm going to go study the code now.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Bulk Find and Replace Whole Words, Not Strings

    Thanks for the feedback.

    The code is doing exactly what you explained.

    1) add a space at both ends in the cell. (no loop)
    2) replace what is in col.F added a space at both ends with what is in col.G.
    3) trim the range to delete a space at both ends(no loop)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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