View Full Version : Changin the value in the cell as the whole and not as the word in the cell?


darksniper
07-29-2008, 09:20 AM
I have a script that changes country codes into numbers. The issue that I am having at the moment is when I have a cell that contains other words other than the country it changes it too. Also I cannot specify the name of the colum since every excell spreadsheet is different.

Example:

cell 1: Canada
cell 2: In Canada it rains today.

When I would run my Script I would like it to change only Cell 1 since Canada is the only work in the whole cell, and exclude all other cells where Canada is with other words.

so the result would look something like this:

cell 1: 1
cell 2: In Canada it rains today.

Here is part of the script I have. How can I improove it?

Sub MacroCountry()
'
' MacroCountry Macro
' Macro recorded 12/11/2007
'
' Keyboard Shortcut: Ctrl+Shift+Y
'
Cells.Replace What:="Canada", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False


Thx.

Brianwarnock
07-29-2008, 10:03 AM
replace LookAt:=xlPart by LookAt:=xlWhole

Brian

darksniper
07-29-2008, 11:14 AM
thank you, it works like a charm.