Excel macro: Replace enitre cell contents; replace 1 but not 10, 11, 21 etc

Posted by user65678 on Super User See other posts from Super User or by user65678
Published on 2011-02-01T19:04:39Z Indexed on 2012/09/30 15:40 UTC
Read the original article Hit count: 266

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.

© Super User or respective owner

Related posts about microsoft-excel

Related posts about macros