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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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