View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike Fogleman Mike Fogleman is offline
external usenet poster
 
Posts: 1,092
Default VBA Conditional formating

You can do this in one large selection and the formulas will auto-adjust the
references if you remove the $ from the formula as needed.
The $ makes the letter or number following it an Absolute reference. Since
you are formatting across multiple columns as well as rows, you have not
provided enough information about what you want for B4, C4, D4, etc. to give
you an exact example for your needs.
The following will format the entire range with each cell refering to the
row it is on, keeping columns M & I constant across the columns.

Sub test()
Range("A4:L150").Select

'Using these three condition
' Always use the following line first for Cond Frmtng
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$M4=""xxxxx"""
Selection.FormatConditions(1).Interior.ColorIndex = 4
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$I4=""yyyyy"""
Selection.FormatConditions(2).Interior.ColorIndex = 38
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$I4=""zzzzzzzz"""
Selection.FormatConditions(3).Interior.ColorIndex = 40
End Sub

Your 4 choices for the formula cell a
M4
$M4
$M$4
M$4

Mike F
"Little Penny" wrote in message
ups.com...
I'm trying to create a conditional format on about 150 rows in my
spreadsheet

Range("A4:L4").Select
Range("A5:L5").Select
Range("A6:L6").Select

Up to

Range("A150:L150").Select

Using these three condition

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$M$4=""xxxxx"""
Selection.FormatConditions(1).Interior.ColorIndex = 4
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$I$4=""yyyyy"""
Selection.FormatConditions(2).Interior.ColorIndex = 38
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$I$4=""zzzzzzzz"""
Selection.FormatConditions(3).Interior.ColorIndex = 40

(In the condition I would use the variable count to go to next row)

I tried creating a loop with a counter but I can't get my variable to
worth in the ranges.

Any help would be greatly appreciated.