Matching strings with a pattern
If your number string is **always** six digits long, you can do this...
Sub ColorCells()
Dim Cell As Range, YourRange As Range
Set YourRange = Worksheets("Sheet2").Range("A1:C100")
YourRange.Interior.ColorIndex = xlColorIndexNone
For Each Cell In YourRange
If Cell Like "* - ######" Then Cell.Interior.ColorIndex = 3
Next
End Sub
I interpreted the OP to mean by "alphabetic" that that string only
contained
letters. Yours will match any character, or even no character, in the
first
part of the string.
As a matter of fact, the "*" is superfluous in your pattern.
Good point Ron! I completely overlooked that. I just posted some corrected
code for the OP (still using the Like operator test method).
Going back to my original code though... what did you mean the "*" is
superfluous in your pattern? If we leave it out, then this test will fail...
If "Mumbai - 400078" like " - ######" Then
Or did I miss the point of your comment?
--
Rick (MVP - Excel)
|