LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 84
Default Conditional Format VB Code for Begins With

Hi

I've cribbed the following code from this site to use for some conditional
formatting. However, i'd like to change it so that if the cells BEGIN WITH
the letters I've put into the code the formatting will work. Plus I'd also
like to format the colour of the text using the same critieria, ie, if the
cell begins with "PM-" then colour the cell and colour the text. I'd be
grateful for any suggestions, thanks.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Range
Set vRngInput = Intersect(Target, Range("A1:iv63000"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case UCase(rng.Value)
Case Is = "PM": Num = 22
Case Is = "BH": Num = 45
Case Is = "H": Num = 4
Case Is = "PE": Num = 35
Case Is = "E": Num = 5
Case Is = "R": Num = 6
Case Is = "P": Num = 29
Case Is = "A": Num = 7
Case Is = "PRE": Num = 8
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

--
Marie Bayes
 
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
If statement - begins with grantr Excel Discussion (Misc queries) 6 October 31st 08 06:35 PM
New Conditional Format Overriding Previous Conditional Format Rene Excel Discussion (Misc queries) 3 February 27th 08 06:08 PM
Code Date Format Depending on Computer format Myriam Excel Discussion (Misc queries) 0 July 17th 07 03:26 PM
IF Function - Begins With Cecil Excel Discussion (Misc queries) 3 November 23rd 05 03:57 PM
Code for Conditional format TUNGANA KURMA RAJU Excel Discussion (Misc queries) 4 November 3rd 05 09:58 AM


All times are GMT +1. The time now is 04:07 AM.

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

About Us

"It's about Microsoft Excel"