Conditional format macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 20 columns in an Excel 2003 spreadsheet. I am not sure how many rows
there are as this could change.

If Column D and Column E are NOT equal, I would like both the cells
(colorIndex to be 40) to be tan

If Column F and Column G are not equal then I would like to shade the cells
tan as above.

Similarly for Columns H and I.

The last row has the word Grand Total in Col A and that the conditional
formatting should not apply to that row.

I know how to do this with conditional formatting but could someone please
help me do this with a macro that I can install on my PC? I have to implement
this formatting for several spreadsheets of various sizes and a macro would
be much easier to use.

Thanks.
 
Sub AddCF()
Dim iLastRow As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row - 1
With Range("D1").Resize(iLastRow, 2)

.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=$D" & ActiveCell.Row & _
"<>$E" & ActiveCell.Row
.FormatConditions(1).Interior.ColorIndex = 40
End With

End Sub


--
HTH

Bob Phillips

(replace somewhere in 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

Back
Top