Excel macro: Replace enitre cell contents; replace 1 but not 10, 11, 21 etc
- by user65678
I need to replace a large amount of numbers with words in an Excel spreadsheet.
Eg:
1 = hello
12 = goodbye
4 = cat
etc. I can do it with the standard search and replace, but i have a large list to work through (about 240 number/word combos), so i figured i would use a macro.
I have this:
Sub findreplacer()
For Each mycell In Range("A1:A1000")
mycell.Replace What:="1", Replacement:="hello"
mycell.Replace What:="12", Replacement:="goodbye"
mycell.Replace What:="4", Replacement:="cat"
Next
End Sub
But it replaces the 1 in 12 so the cell reads hello2 instead of goodbye.
How can i make it just affect cells that only contain the specific number, the way 'match entire cell contents' works?
Any help appreciated.