View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default Multiple Conditional Formatting Using VBA

Hi

You need to process the worksheet_change event and apply your format
based on the cell values).
The following will color the entry in cell A1:C10 based on its value
(put this code in your worksheet module):
You have to adapt the color indexes for each value (have a look at for
color codes

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1:C10")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
Select Case .Value
Case "D": .interior.ColorIndex = 3
Case "N":
.interior.ColorIndex = 4
.Font.ColorIndex = 3
Case "DC": .Interior.ColorIndex = 10
'etc.
End Select
End With
CleanUp:
Application.EnableEvents = True
End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Hi,

I would like to conditionally format two and sometimes three areas of
cells on the same worksheet, however all of these areas need more

than
three conditions and therefore has to be done through VBA. However I
am not very advanced at writting VBA code and would like some help
please.

Here is a mini version of my problem:

In cells A1:C10,
when D is typed in I would like the background colour to change to
light blue,
when N is typed in I would like the background colour to change to
dark blue and the font colour to white
DC background colour to light purple
NC background colour to dark purple and font to white

Also
In cells A11:C20,
when D is typed in I would like the background colour to change to
gold,
DC background colour to light purple
NC background colour to dark purple and font to white
S background colour to pink
L background colour to light grey

and on some worksheets:
In cells A21:C30,
when D is typed in I would like the background colour to change to
light green,
when N is typed in I would like the background colour to change to
dark green and the font colour to white
DC background colour to light purple
NC background colour to dark purple and font to white

In all cases when anything else is typed in, including numbers, I
would like it to ingore them so the background and colours can be
changed manually or left blank


I think this has to be a change event individual to each sheet, as
each sheet requires different colour combinations, but that is about
as far I know.

Thanks in advance
Jennie


---
Message posted from http://www.ExcelForum.com/