+ Reply to Thread
Results 1 to 3 of 3

Find and replace multiple words

Hybrid View

bumbar Find and replace multiple... 03-09-2013, 02:53 AM
jindon Re: Find and replace multiple... 03-09-2013, 04:05 AM
bumbar Re: Find and replace multiple... 03-09-2013, 04:28 AM
  1. #1
    Registered User
    Join Date
    05-18-2012
    Location
    Slovenia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Find and replace multiple words

    Hi all, I am new to VBA and I try to create macro which will find and replace multiple words from different sheets.

    Here is an example for better understanding
    In one workbook I have two sheets
    First sheet named "work" - I have data in column C that I would like to replace with some other data. Range will wary so once will be "C1:C563" and some other time it will be "C1:C1456" and so on...But it will always be column C

    Second sheet named "base" Here is my find and replace text - base to do find and replace - and it has two columns. In column "A" is my search term (data in sheet "base" column "A" is the same as some data in sheet "work" column "C") and in same sheet ("base") in column B which is replace data.

    I want to replace text in same row - example: i want to find data in sheet "base" in column A, to find it in sheet "work" in column "C" and replace it with text in sheet "base" with data in column "B".

    And find and replace data in sheet "base" is always in same row (A1 with B1, A2 with B2...).
    Example:
    Text in sheet("base) cell A1 find this text in sheet("work") range C and replace it with text in sheet("base") cell B1
    then Text in sheet("base) cell A2 find this text in sheet("work") range C and replace it with text in sheet("base") cell B2
    then Text in sheet("base) cell A3 find this text in sheet("work") range C and replace it with text in sheet("base") cell B3
    and so on and so on till A520.

    I hope you understand what I want to to do

    Thanks for any help!

    I found this code but Ir replaces me with empty cells...

    HTML Code: 
    Last edited by bumbar; 03-09-2013 at 03:11 AM.

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

    Re: Find and replace multiple words

    Perhaps
    Sub test()
        Dim r As Range
        For Each r In Sheets("base").Cells(1).CurrentRegion.Columns(1).Cells
            Sheets("work").Columns("c").Replace r.Value, r(, 2).Value, 2
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    05-18-2012
    Location
    Slovenia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Find and replace multiple words

    This is perfect!! Thanks

+ 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