Macro to run find and replace.

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello all,

I was trying to see if this was possible. To have a macro select the range m3:x12 and then do a find and replace:
find the value in > replace with value of
A2 B2
A3 C2
A4 D2
A5 E2
A6 F2


amy help would be greatly appreciated.
 
Macro recorder doesn't appear to be useful for this. I can't search for cell references.
 
Upvote 0
Try:

Code:
Sub Replace_By_Position()
Dim i As Integer
Dim sOld As String, sNew As String

For i = 2 To 6
    sOld = Cells(i, 1)
    sNew = Cells(i, 2)
    Range("M3:X12").Replace sOld, sNew, xlPart
Next i
End Sub

Since a worksheet isn't specifically mentioned it works on the ActiveSheet.
 
Upvote 0

Forum statistics

Threads
1,226,849
Messages
6,193,331
Members
453,790
Latest member
yassinosnoo1

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