+ Reply to Thread
Results 1 to 4 of 4

Find & Replace VBA

  1. #1
    Registered User
    Join Date
    06-06-2008
    Posts
    89

    Find & Replace VBA

    Greetings,

    I need to perform a 'find and replace' on a worksheet to change all references to a particular month to the following month i.e. find “Month **” (**=could be any number 01 - 12) and replace with the contents of cell “AE2” (the cell reference where the current Month ** is generated).

    I have written the very simple code below and assigned it to a button so that it can be used by multiple staff in the department, and the find and replace part is seemingly fine. However, when replacing with the new text, it doesn’t just replace Month ** with Month **, it also removes any other text that may have been present in the cell after Month ** is present

    Please Login or Register  to view this content.
    For example:

    ‘Financial Statements Month 05 2014/15’ becomes ‘Financial Statements Month 06’ (' 2014/15' is lost)

    But more importantly, the filepath which drives the attachment on the subsequent mail merge changes from:

    ‘N:\folder 1\folder 2\Month 05\filename.xls’ to N:\folder 1\folder 2\Month 06’. ('\filename.xls' is lost)

    The path is therefore incomplete and the attachment is not added to the email.



    Is there a way of altering my code so that the replace will work mid-text string and keeping everything else as it originally was?

    many thanks in advance.

    Phil

  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 & Replace VBA

    Use ?? instead of **
    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
    Registered User
    Join Date
    06-06-2008
    Posts
    89

    re: Find & Replace VBA

    Quote Originally Posted by Olly View Post
    Use ?? instead of **
    It only just went and bloomin worked!!!
    So simple too

    Many thanks

  4. #4
    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 & Replace VBA

    Quote Originally Posted by philwilliams80 View Post
    It only just went and bloomin worked!!!
    So simple too

    Many thanks
    The simple fixes are the best Thanks for the feedback.

+ 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. [SOLVED] find and replace to not replace characters found as wildcards
    By sabutler4 in forum Excel General
    Replies: 4
    Last Post: 07-03-2013, 06:48 PM
  2. 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
  3. Multiple Find and Replace to replace a list of strings
    By WalterP34 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2011, 07:41 PM
  4. Find/Replace Macro Using Replace Table
    By LampCommandr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2011, 11:00 AM
  5. find and replace - replace data in rows to separated by commas
    By msdker in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-14-2006, 08:10 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