I am currently using this code to replace words in my data:
Sub MultiReplace()
On Error GoTo errorcatch
Dim arrRules() As Variant
strSheet = "renamelist"
strRules = "A1:A100"
Set rngCol1 = Sheets(strSheet).Range(strRules)
Set rngCol2 = rngCol1.Offset(0, 1)
arrRules = Application.Union(rngCol1, rngCol2)
For i = 1 To UBound(arrRules)
Selection.Replace What:=arrRules(i, 1), Replacement:=arrRules(i, 2), _
LookAt:=xlWhole, MatchCase:=True
Next i
errorcatch:
End Sub
The tab containing my data is copied into another file and the renamelist tab isn't. I can't put the renamelist onto columns on the main tab because my users wipe it out. Is it possibly to hardcode the renamelist data into the code and avoid having one hundred of these lines?
Cells.Replace What:="Apples", Replacement:="Red", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Pears", Replacement:="Blue", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Bananas", Replacement:="Green", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sub MultiReplace()
On Error GoTo errorcatch
Dim arrRules() As Variant
strSheet = "renamelist"
strRules = "A1:A100"
Set rngCol1 = Sheets(strSheet).Range(strRules)
Set rngCol2 = rngCol1.Offset(0, 1)
arrRules = Application.Union(rngCol1, rngCol2)
For i = 1 To UBound(arrRules)
Selection.Replace What:=arrRules(i, 1), Replacement:=arrRules(i, 2), _
LookAt:=xlWhole, MatchCase:=True
Next i
errorcatch:
End Sub
The tab containing my data is copied into another file and the renamelist tab isn't. I can't put the renamelist onto columns on the main tab because my users wipe it out. Is it possibly to hardcode the renamelist data into the code and avoid having one hundred of these lines?
Cells.Replace What:="Apples", Replacement:="Red", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Pears", Replacement:="Blue", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Bananas", Replacement:="Green", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False