LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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)



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pattern Matching [email protected] Excel Discussion (Misc queries) 6 September 24th 07 09:19 PM
Pattern Matching using LIKE ? Jakobshavn Isbrae Excel Programming 2 December 31st 06 01:18 PM
VBE replace with pattern matching? RB Smissaert Excel Programming 2 August 13th 06 02:18 PM
pattern matching possible? vito Excel Worksheet Functions 1 May 16th 06 05:03 PM
Pattern Matching with cells function John[_80_] Excel Programming 2 June 29th 04 04:51 AM


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"