View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Conditional formatting within macro?

Hi Jonathan,

Am Tue, 26 Mar 2013 14:39:17 +0000 schrieb JonathanK1:

I know how to use conditional formatting within the excel sheet, but I
want to integrate it into a macro (the macro is doing other things as
well). Is this possible?

Basically, there is a column for the age of a car. The macro is pulling
the data and pasting it into a new workbook - but when it's pasted/as
it's pasted, I want anything older than 2008 (age in column Q) to become
red (the cell that is). Is this possible?


implement to your existing code:

Dim LRow As Long

LRow = Cells(Rows.Count, "Q").End(xlUp).Row
Range("$Q$2:$Q$" & LRow).Select
With Selection
.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q2<2008"
.FormatConditions(.FormatConditions.Count).SetFirs tPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2