Tigerexcel
Active Member
- Joined
- Mar 6, 2020
- Messages
- 493
- Office Version
- 365
- 2019
- Platform
- Windows
I have a macro that I use to perform bulk find and replace which works well however the codes change from time to time. I'd like to know how I can vary this macro to pick up the code straight from a worksheet into the macro because at the moment I type the information straight in which can lead to errors particularly when there are lots of entries to change.
Next week codes could be something like:
123
560
417
200
The respective replacements would be:
Biology
Science
Philosophy
Zoology
I've simplified the data but hopefully I've made it clear
VBA Code:
Sub Tracker()
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("230", "300", "114", "470")
rplcList = Array("Business", "Chemistry", "Engineering", "Arts")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what:=fndList(x), replacement:=rplcList(x), _
Lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End sub
Next week codes could be something like:
123
560
417
200
The respective replacements would be:
Biology
Science
Philosophy
Zoology
I've simplified the data but hopefully I've made it clear