+ Reply to Thread
Results 1 to 7 of 7

Thread: Find/Replace en masse using multiple cells

  1. #1
    Registered User
    Join Date
    01-17-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Find/Replace en masse using multiple cells

    I am trying to find code for an excel marco that will allow me to use the find/replace function on mass. I have a large excel sheet and then two control columns where one columns value needs to replace second columns value...

    So...
    Find G5, replace with H5 in all document;
    Find G6, repalce with H6 in all document;
    Find G7, repalce with H7 in all document;
    ...
    Find G210, replace with H210 in all document;


    The actual value found for the searched item (G#) needs to match completely.
    I've seen tons of macros for replace a single word but couldn't find any for cells and then having them repeat.
    Any ideas?

  2. #2
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: Find/Replace en masse using multiple cells

    Can you post a dummy workbook with a before and after on how you want it to work? And what are you trying to match column G with?
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  3. #3
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Find/Replace en masse using multiple cells

    Sorry guys, but JapanDave, are you able to help with another request from Lifeseeker?

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Find/Replace en masse using multiple cells

    Something like this should do it, just make sure your control sheet is active when you run it, it will execute the REPLACE function on all the other sheets.

    Sub MassReplace()
    Dim ws As Worksheet
    Dim valRNG As Range, v As Range
    
    With ActiveSheet
        Set valRNG = .Range("G:G").SpecialCells(xlConstants)
        
        For Each v In valRNG
            For Each ws In Worksheets
                If ws.Name <> .Name Then
                    ws.Cells.Replace v.Value, v.Offset(, 1).Value, xlWhole
                End If
            Next ws
        Next v
    End With
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    01-17-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Find/Replace en masse using multiple cells

    Here is a sample of the data. I need to search E for any item that equals H and replace it with G.

    A B D E F G H
    Control # PRODUCT#........ ON WLOC. New WLOC Old WLOC
    153 W88-997 2 10K1 L-06-01-A 10K1
    154 W89-250 2 10K1 L-06-01-B 10K2
    155 667236 2 10K10 L-06-01-C 10K3
    156 667303 3 10K2 L-06-01-D 10K4
    157 W89-017 3 10K2 L-06-01-E 10K5
    158 W91-141 1 10K2 L-06-01-F 10K6
    159 W89-726 0 10K3 L-06-01-G 10K7
    160 W89-739 0 10K3 L-06-01-H 10K8
    161 667286 1 10K4 L-06-01-I 10K9
    162 70-42268-01 0 10K4 L-06-01-J 10K10
    163 1085841 0 10K5 L-06-02-A 10L1
    164 W89-527 1 10K5 L-06-02-B 10L2
    165 W89-737 3 10K6 L-06-02-C 10L3
    166 W89-712 1 10K7
    167 W89-305 1 10K8
    179 5308006930 0 10L2
    180 60542001 2 10L2

  6. #6
    Registered User
    Join Date
    01-17-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Find/Replace en masse using multiple cells

    Attachment 136989 I'm trying to post a picture of the worksheet

    Location changes.jpg This is with changes for a few of the items.

    Thanks for any help!!
    Last edited by kenyacoastie; 01-18-2012 at 11:31 AM.

  7. #7
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Find/Replace en masse using multiple cells

    So....
    Sub MassReplace()
    Dim ws As Worksheet
    Dim valRNG As Range, v As Range
    
    With ActiveSheet
        Set valRNG = .Range("H:H").SpecialCells(xlConstants)   'terms to search for
        
        For Each v In valRNG
            For Each ws In Worksheets
                If ws.Name <> .Name Then
                    ws.Range("E:E").Replace v.Value, v.Offset(, -1).Value, xlWhole  'replaces with value 1 column to the left of the searched value
                End If
            Next ws
        Next v
    End With
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0