+ Reply to Thread
Results 1 to 3 of 3

Replace specific text in workbook

  1. #1
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    174

    Replace specific text in workbook

    Hi all,

    I have a userform which opens when you select a cell, in this userform a label (called CurrentName) will read what the contents of the active cell are. There is also a texbox in the userform (called NewName).

    The purpose of this is essentially like a replace all function but within a userform. The code reads the value of the current cell and then the user can chose something new in the textbox and the code will find all references to the currentname and replace them with the newname.

    At the moment it is working however it appears to have a slight issue in that it is replacing any instance of the word found rather than whole cell value. So for example, if I have 'Hello' in the active cell and 'Hello Two' in another cell, when I select to change it to 'Goodbye' it will change both 'Hello' to 'Goodbye' but also will change 'Hello Two' to 'Goodbye Two', whereas I would rather the second example stayed as 'Hello Two' because I only want to replace instances where 'Hello' is the only value in the cell, not where it appears with other values as well.

    I hope that makes sense. It's probably something really obvious I have overlooked but would appreciate the help. Here is my code so far:

    Please Login or Register  to view this content.
    Excel Beginner

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,093

    Re: Replace specific text in workbook

    Try changing LookAt:=xlPart to LookAt:=xlWhole

  3. #3
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    174

    Re: Replace specific text in workbook

    Wow. I knew it would end up being something stupid I missed.

    I was trying all kinds of things in the code with Like/Not Like/<> or with *.

    Shaking my head right now.

    Thanks!

+ 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. Replies: 1
    Last Post: 02-02-2018, 04:57 AM
  2. Replies: 1
    Last Post: 07-20-2016, 10:12 AM
  3. Lookup & replace specific text in a text string
    By Haha88 in forum Excel General
    Replies: 1
    Last Post: 07-13-2015, 06:06 PM
  4. Replies: 2
    Last Post: 04-10-2015, 12:12 PM
  5. [SOLVED] Search through columns and find specific text and replace that text with header column
    By adamzee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2014, 11:59 PM
  6. Replacing specific text in a cell by row and replace with text in another row
    By merQrey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2014, 10:05 AM
  7. Find & Replace in all Workbook (Read all Names from Specific Column)
    By dim06 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-15-2012, 09:45 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