+ Reply to Thread
Results 1 to 11 of 11

Find and replace with exact string

  1. #1
    Registered User
    Join Date
    11-26-2013
    Location
    Leclaire, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    7

    Find and replace with exact string

    I need to find an exact string (i.e. "Room 1,2,3,4") in a sheet and replace it with another exact string (i.e. "Room 1, Room 2, Room 3, Room 4") in the same sheet.

    How do I denote an exact string?

    The problem I am having is:
    find "Room 1,2,3", replace with "Room 1, Room 2, Room 3" and find "Room 1,2" and replace with "Room 1, Room 2" in the same sheet is finding "Room 1,2" within "Room 1,2,3" and replacing it with "Room 1, Room 2,3".

    How could I make a more general find and replace that deals with all of these possible combinations?
    How do I denote an EXACT string in VBA?
    Last edited by carrie.cllek; 11-27-2013 at 04:04 PM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Find and replace with exact string

    What code are you currently using to find and replace?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find and replace with exact string

    Hi,

    If the cells contain just that information, and you are able to select these cells only as your range, can you not simply do a Find and Replace with:

    Find what: ,
    Replace with: , Room

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and replace with exact string

    As recommended by OllyXLS it would be best to see your code, so that we can determine what would/could cause the mistakes.

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Find and replace with exact string

    Hi and welcome to the forum

    This is not VBA, and is a bit messy, but you could put this in a helper column, copied down...
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,",2",", Room 2"),",3",", Room 3"),",4",", Room 4")

    Then if you want, copy/paste values over the original data andthen delete the helper
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

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

    Re: Find and replace with exact string

    Assuming the data in col.A

    Converts
    Room 1,2,3,4 to Room 1, Room 2, Room 3, Room 4
    Room 2,5,12 to Room 2, Room 5, Room 12
    etc.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-26-2013
    Location
    Leclaire, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Find and replace with exact string

    This is my current code:

    Please Login or Register  to view this content.
    If the order if reversed, the macro finds "Ws; Rooms 1,2" in "Ws; Rooms 1,2,3" and changes it to "Meeting Room 1 | Meeting Room 2,3"

    How can I denote the exact string, nothing more, nothing less.

    Thank you all!

    Moderators note: code tags added for you - this time
    Last edited by FDibbins; 11-27-2013 at 03:28 PM.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Find and replace with exact string

    carrie....Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Find and replace with exact string

    One method:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-26-2013
    Location
    Leclaire, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Find and replace with exact string

    Thanks so much! I'm still new at this and I really appreciate everyone's help!

  11. #11
    Registered User
    Join Date
    11-26-2013
    Location
    Leclaire, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Find and replace with exact string

    Thank you so much OllyXLS!

    That code is very helpful and solved the problem!

+ 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. Find an exact word within a text string
    By juanmimr in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-08-2013, 10:30 AM
  2. [SOLVED] Find a string by VBA Regular Expression and replace a part of that string
    By taps in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2013, 11:08 AM
  3. [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
  4. Replace Exact String Portion
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2011, 11:36 AM
  5. macro find&replace only exact value
    By DMR1712 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2009, 06:04 AM

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