Trying to make replacements to raw data which comes in all sorts of variations eg Diploma could be dip, DP, Dipl. I've tried a macro but it doesn't do anything and that may be because I'm using a work computer. Looking for a formula to help convert the raw data with what's in the accompanying table. To be on the safe side, I'll need the formula to work on Office 2019 as I have a spare computer with that on it. If there's an obvious problem with my macro, then I'll fix it but I've used macros like these before and they've been fine so a formula/function will probably be how I go on this one. If there's an easier way to do it on Office 365, I'll look at that too. Open to suggestions here because I spend a lot of time cleaning data which is inconsistently entered.
The macro is
Sub MultiReplace()
Dim ListItem As Range
Dim ListToReplaceWithin As Range
Dim ListOfThingsThatWillChange As Range
On Error GoTo ErrorHandler
Set ListToReplaceWithin = Application.InputBox(Prompt:="Select the list you want to replace within:", Title:="Replace Items", Type:=8)
Set ListOfThingsThatWillChange = Application.InputBox(Prompt:="Select the list of items that you want to change:", Title:="Replace With", Type:=8)
For Each ListItem In ListOfThingsThatWillChange
ListToReplaceWithin.Replace What:=ListItem, Replacement:=ListItem.Offset(0, 1)
Next ListItem
Exit Sub
ErrorHandler:
Exit Sub
End Sub
Multireplace macro.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | Should read | Table for macro | ||||||
2 | Course | Course | Old | New | ||||
3 | Adv Dip Science | Advanced Diploma Science | Adv | Advanced | ||||
4 | As Deg Business | Associate Degree Business | Dip | Diploma | ||||
5 | D Bus | Diploma Business | D | Diploma | ||||
6 | Cer Maths | Certificate Maths | Cer | Certificate | ||||
Sheet1 |
The macro is
Sub MultiReplace()
Dim ListItem As Range
Dim ListToReplaceWithin As Range
Dim ListOfThingsThatWillChange As Range
On Error GoTo ErrorHandler
Set ListToReplaceWithin = Application.InputBox(Prompt:="Select the list you want to replace within:", Title:="Replace Items", Type:=8)
Set ListOfThingsThatWillChange = Application.InputBox(Prompt:="Select the list of items that you want to change:", Title:="Replace With", Type:=8)
For Each ListItem In ListOfThingsThatWillChange
ListToReplaceWithin.Replace What:=ListItem, Replacement:=ListItem.Offset(0, 1)
Next ListItem
Exit Sub
ErrorHandler:
Exit Sub
End Sub