Multiple Find & Replace a String within Cells based on List

kaiday

New Member
Joined
May 28, 2015
Messages
1
I tried to run the vb code below to replace a list of strings with another but it doesnt work. For example, on Sheet2, in the A column I have a list of strings that I want to be found and replaced with the list of strings in B. So in A1 I have Apple and in B1 I have Banana. Now anywhere on Sheet1 there is an Apple I want Banana. The issue with the code is that it will only replace cells that say only Apple with Banana. I have many cells on sheet 1 that say AppleSauce in cells that should say BananaSauce. Can this find and replace be manipulated to find and replace an exact string and not exact cells. Thank you for the help!



Code:
Sub Macro1()
Dim i As Integer
Dim FindStr As String
Dim RepStr As String
For i = 1 To 20
    FindStr = Sheet2.Range("A" & i).Value
    RepStr = Sheet2.Range("B" & i).Value
    
    Sheet1.Cells.Replace What:=FindStr, Replacement:=RepStr
Next i
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,215,063
Messages
6,122,927
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top