Nov 01 2020 10:17 PM
Hello everyone!
I have been trying to build some macro to find and replace multiple values in selected cells as below,
Sub FR()
Dim rngCell As Range
Dim fndList As Variant
Dim rplcList As Variant
Dim F As Long
fndList = Array("United Kingdoms", "United States", "Australia")
rplcList = Array("UK", "US", "AUS")
For F = LBound(fndList) To UBound(fndList)
For Each rngCell In Selection
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next Rng
Next F
End Sub
But I am having errors. Can you guys help this?
Many thanks,
Young
Nov 01 2020 10:42 PM
Solution@Youngmrr Try it this way:
Sub FR()
Dim fndList As Variant
Dim rplcList As Variant
Dim F As Long
fndList = Array("United Kingdom", "United States", "Australia")
rplcList = Array("UK", "US", "AUS")
For F = 0 To UBound(fndList)
Selection.Replace What:=fndList(F), Replacement:=rplcList(F), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next F
End Sub
Nov 04 2020 04:12 PM
@Riny_van_Eekelen It works!!! Thank you so much for your help! :)
Nov 01 2020 10:42 PM
Solution@Youngmrr Try it this way:
Sub FR()
Dim fndList As Variant
Dim rplcList As Variant
Dim F As Long
fndList = Array("United Kingdom", "United States", "Australia")
rplcList = Array("UK", "US", "AUS")
For F = 0 To UBound(fndList)
Selection.Replace What:=fndList(F), Replacement:=rplcList(F), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next F
End Sub