M
Marie Bayes
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
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