+ Reply to Thread
Results 1 to 7 of 7

Macro for Multiple Find and Replace in Excel

  1. #1
    Registered User
    Join Date
    06-27-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Red face Macro for Multiple Find and Replace in Excel

    Hi, please see attached document.

    I'm trying to get a macro that will automatically replace all the contents in tab "contracts" with the corresponding number in tab "list of BUs" - i.e. change "H0041" to "40" etc.

    I would also ideally like a macro that would then allow me to change back the other way - i.e. change the "40" back to "H0041".

    Would be grateful for any help.

    Regards
    Last edited by lxlth20000; 06-27-2013 at 11:16 AM.

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Macro for Multiple Find and Replace in Excel

    I looked at list of BU but only found the code and the name. Do you need to toggle between these two?

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro for Multiple Find and Replace in Excel

    Your List of BU's only has the H0041 number and company name. It doesnt have the 40. That being said your code would be something like:
    Please Login or Register  to view this content.
    Based on the replacement values being in column C in the List of Bus sheet.

  4. #4
    Registered User
    Join Date
    06-27-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro for Multiple Find and Replace in Excel

    Thank you and apologies for the confusion over s/s.

    Example.xlsm

    I've now re-attached a more simplified version of s/s. I have also added in it the macro that yudlugar recommended with the slight edit of changing the replacement range to column B rather than C, so it is as below:

    Sub Replace()
    Dim count
    For count = 2 To Sheets("List of BUs").Range("A" & Rows.count).End(xlUp).Row
    Sheets("Management Contract").Cells.Replace What:=Sheets("List of BUs").Range("A" & count), _
    Replacement:=Sheets("List of BUs").Range("B" & count)
    Next
    End Sub

    However, whilst this works in replacing the values in the first tab (which is what I want), it also seems to replace the values in tab "List of BUs" as well, whereas I just want to limit the find and replace to the first tab (hopefully this will make more sense if you actually run the macro as attached). Not sure if a slight tweak is needed in the macro?

    Also, any macro in doing the reverse - i.e. doing a find a replace from company name to company code. Ideally I'd like two macro that both refer to the one list in "List of BUs" tab.

    Many thanks for help

  5. #5
    Registered User
    Join Date
    06-27-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro for Multiple Find and Replace in Excel

    Sorry, I've reattached (see penultimate post) a more simplified s/s, but in essence yes, I need to toggle between code and name. Thanks.

    Quote Originally Posted by rcm View Post
    I looked at list of BU but only found the code and the name. Do you need to toggle between these two?

  6. #6
    Registered User
    Join Date
    06-27-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro for Multiple Find and Replace in Excel

    *bump*

    Would be grateful for any further help on this...?

  7. #7
    Registered User
    Join Date
    07-01-2013
    Location
    mumbai
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Macro for Multiple Find and Replace in Excel

    Can you please attach the document...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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