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