+ Reply to Thread
Results 1 to 8 of 8

Use Replace Function to Replace Whole Word

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Use Replace Function to Replace Whole Word

    Hello,

    How Can I Use the --Replace-- function to replace whole word (instead or partial)

    Sub TestFindReplace()
        
        strToReplace = "Range(""Sh01Start""), Range(""Sh01StartEnd"")"
        
        strAfterReplace = Replace(strToReplace, "Sh01Start", "Sh01End", Start:=1, Count:=-1, compare:=vbBinaryCompare)
        
        Debug.Print strAfterReplace
    
    End Sub
    The result of the above sub is:

    Range("Sh01End"), Range("Sh01EndEnd")
    Expected Result With Whole Word Replacement is

    Range("Sh01End"), Range("Sh01StartEnd")
    Thank you.
    Attached Files Attached Files

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

    Re: Use Replace Function to Replace Whole Word

    Do you mean?
        strAfterReplace = Replace(strToReplace, """Sh01Start""", """Sh01End""", Start:=1, Count:=-1, compare:=vbBinaryCompare)

  3. #3
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Use Replace Function to Replace Whole Word

    I want to use replace function to replace whole word for many strings not only for the above example. (the above macro is just for demonstration)

  4. #4
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Use Replace Function to Replace Whole Word

    If this replace function doesn't replace whole word, is there an alternative function can replace whole word?

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

    Re: Use Replace Function to Replace Whole Word

    You said,
    Quote Originally Posted by exceere View Post

    The result of the above sub is:

    Range("Sh01End"), Range("Sh01EndEnd")
    Expected Result With Whole Word Replacement is

    Range("Sh01End"), Range("Sh01StartEnd")
    So, I posted my suggestion.
    Anything wrong?

  6. #6
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Use Replace Function to Replace Whole Word

    This, just was an example to describe the idea (Replace Whole Word).

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

    Re: Use Replace Function to Replace Whole Word

    Then post a better sample.

  8. #8
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Use Replace Function to Replace Whole Word

    jindon,

    I appreciate your effort.

+ 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. Excel VBA - Word to search for part of a word and replace full word
    By charlie543 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-24-2016, 02:56 AM
  2. REPLACE function help replace two separate texts Ctrl H
    By Uldis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-23-2015, 10:51 AM
  3. Replies: 3
    Last Post: 11-25-2014, 06:08 AM
  4. [SOLVED] Need help with REPLACE function to replace HEX A0 with HEX 20 in string
    By flyboy54 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2013, 12:52 PM
  5. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM
  6. Vlookup Function to replace word
    By rupss01 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-01-2011, 01:25 PM
  7. Replace Function:Replace" and type in
    By ronnyc in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-19-2007, 06:26 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