Help with vba! Multiple finds and replacements

sbehiar

New Member
Joined
Jun 14, 2013
Messages
3
Hello Excel experts,

Am trying to run the following macro, but it gives an error which is not quite clear to me:


Sub FindAndReplace()
Dim oWB As Workbook
Dim oSheetA As Worksheet
Dim oSheetB As Worksheet
Dim LastRow As Long
Dim A As Long
Dim Rng As Range

Set oWB = ThisWorkbook
Set oSheetA = oWB.Worksheets("A")
Set oSheetB = oWB.Worksheets("B")

LastRow = oSheetA.Range("A10000").End(xlUp).Row
Set Rng = oSheetB.UsedRange

For A = 1 To LastRow
With Rng.Find
Do While .Execute(Findtext:=oSheetA.Range("A" & A).Text, Forward:=True) = True
Rng.Text = oSheetA.Range("B" & A).Text
'Rng.HighlightColorIndex = wdYellow
Set Rng = oSheetB.UsedRange
Loop
End With
Next

Set oSheetA = Nothing
Set oSheetB = Nothing
Set oWB = Nothing
End Sub



The following section "With Rng.Find" gives the following warning Compile Error: Argument not optional.

Seems as if I have not defined the worksheet or the range correctly. Can anyone help please?

Thanks,

Sam
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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