I have a workbook with multiple sheets.
The first sheet, "Task", contains the data.
The other sheets are lists for find and replace operations.
I have run the Sub successfully, replacing the data in one column (E) in my first sheet ("Task") with data from other sheets "Salary" & "HR".
Now, I need to perform a find and replace in another column (N) in the "Task" sheet, using data from the "Adm. list" sheet.
This gives me an error message:
Sub FindAndReplace()
Dim TaskWorksheet As Worksheet
Dim searchRange As Range
Dim replaceTable As Variant
Dim findWhat As String
Dim replaceWith As String
Dim i As Long
Set TaskWorksheet = ThisWorkbook.Worksheets("Task")
With TaskWorksheet
Set searchRange = .Range("E2:E" & .Cells(.Rows.Count, "E").End(xlUp).Row)
End With
With ThisWorkbook.Worksheets("HR")
replaceTable = .Range("A1:B" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
End With
With ThisWorkbook.Worksheets("Adm")
replaceTable = .Range("A1:B" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
End With
Set TaskWorksheet = ThisWorkbook.Worksheets("Task")
With TaskWorksheet
Set searchRange = .Range("N2:N" & .Cells(.Rows.Count, "E").End(xlUp).Row)
End With
With ThisWorkbook.Worksheets("HR list")
replaceTable = .Range("A2:B" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
End With
For i = 1 To UBound(replaceTable)
findWhat = replaceTable(i, 1)
replaceWith = replaceTable(i, 2)
searchRange.Replace _
What:=findWhat, _
replacement:=replaceWith, _
lookat:=xlPart, _
MatchCase:=False
Next i
End Sub