View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Conditional Formatting

Assuming you want the IF statement to change rows accordingly, this worked
for me. Test it before permanent installation.


Sub Format1()
'
' Format1 Macro
Range("A26").Activate
'
With Range("E26:H2000")

.FormatConditions.Delete

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(OR($H26=""Please Book"", $H26=""Please Cancel""),TRUE,FALSE)"
.FormatConditions(1).Interior.ColorIndex = 3

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(OR($H26=""Booked"", $H26=""Booked (Time
Changed)""),TRUE,FALSE)"
.FormatConditions(2).Interior.ColorIndex = 4

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF($H26=""Change"",TRUE,FALSE)"
.FormatConditions(3).Interior.ColorIndex = 45

End With

End Sub


"Francis Brown" wrote in message
...
Hi All

Thanks for looking, the help of this forum is always apreciated.

I have the following bit of code:

Sub Format1()
'
' Format1 Macro
'
With Range("E26:H26")

.FormatConditions.Delete

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(OR($H26=""Please Book"", $H26=""Please Cancel""),TRUE,FALSE)"
.FormatConditions(1).Interior.ColorIndex = 3

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(OR($H26=""Booked"", $H26=""Booked (Time
Changed)""),TRUE,FALSE)"
.FormatConditions(2).Interior.ColorIndex = 4

.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF($H26=""Change"",TRUE,FALSE)"
.FormatConditions(3).Interior.ColorIndex = 45

End With

End Sub

This adds the conditioanl formatting I want to row 26.

I need this to also loop down to about row 2000.

Is the best option:

1. can the 26's in my above code be set as a variable and then use a loop
such as "For I = 26 to 2000".

2. set one line as above then copy and paste to the rest.

I also had a little side question. When setting the formula1 condition in
both conditional formatting as above and when you are are setting
validation
rules on a cell when you do it manually you can set the formaulla to refer
to
cell in which you are evaluating the validation or conditional formatting.
Can you use the activecell variable to do this in VBA code.
--
Regards and Thanks for any assistance.

Francis Brown.