Greater than 3 condtional formating rules in Excel

J

John Davies

As the conditional formating command allows only 3 formats, is it possible to
have more than 3 conditional formats using cod?
e.g. cell a1 would display red background if cell a2 = a
cell a1 would display underlined text if cell a3 = b
cell a1 would display bold text if cell a4 = c
cell a1 would display bold italic text if cell a5 = d etc.

Thanks in advance of any help
John
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A2:A5" '<== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address(False, False)
Case "A2":
If .Value = "a" Then
Me.Range("A1").Interior.ColorIndex = 3 'red
Else
Me.Range("A1").Interior.ColorIndex =
xlColorIndexNone
End If
Case "A3":
Me.Range("A1").Font.Underline = .Value = "b"
Case "A4":
Me.Range("A1").Font.Bold = .Value = "c"
Case "A5":
Me.Range("A1").Font.Bold = .Value = "d"
Me.Range("A1").Font.Italic = .Value = "d"
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top