View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
DEE DEE is offline
external usenet poster
 
Posts: 250
Default Conditional Formatting of Cell

Barb, is there a way to code the range for the statement "Set myRange =
Range("C1:C10") " my db will update each month and add rows. Dont want to
have to change code every month.

Thanks,
DC

--
DC


"Barb Reinhardt" wrote:

Try this. It will set the conditional format of the cells in the range based
upon the value in the cell to the RIGHT.

Dim myRange As Range
Set myRange = Range("C1:C10")
With myRange
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=RC[1]=""PASS"""
.FormatConditions(1).Interior.ColorIndex = 4
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=RC[1]=""WATCH"""
.FormatConditions(2).Interior.ColorIndex = 6
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=RC[1]=""FAIL"""
.FormatConditions(3).Font.ColorIndex = 2
.FormatConditions(3).Interior.ColorIndex = 3
End With

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Dee" wrote:

Hello, I have a worksheet whos data comes from SQL Server db. Autofilter is
turned on. Within the worksheet are many columns. I would like to change
the backcolor of the cells in column C based on the content of the
cell in column D (could be "PASS", "WATCH", or "FAIL") on the same row
(i.e. c1=5 d1='Pass' change backcolor of c1
to Green, or c1=7 d1='WATCH' change backcolor to Yellow, or c1=10 d1='FAIL'
change backcolor to Red). How do I identify the range and apply correct
backcolor to cells within range? Need to be coded using vba macro? --
DC

--
Dee