Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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? Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]() |
|||
|
|||
![]() Quote:
Doh! I appreciate your help :) J- |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Jonathan,
Am Wed, 27 Mar 2013 10:45:27 +0000 schrieb JonathanK1: It acted like it was going to work and then stopped, highlighting the ".FormatConditions(.FormatConditions.Count).SetFir st Priority" section. do you have other conditional formattings in your sheet? What Excel version do you use? Try: Sub test() 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" With .FormatConditions(1).Interior .ColorIndex = 3 End With End With End Sub and if it doesn't work, try: Sub test2() Dim LRow As Long Dim rngC As Range LRow = Cells(Rows.Count, "Q").End(xlUp).Row For Each rngC In Range("$Q$2:$Q$" & LRow) rngC.Interior.ColorIndex = IIf(rngC < 2008, 3, xlNone) Next End Sub Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 |
#5
![]() |
|||
|
|||
![]() Quote:
J- |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Claus,
I need to put a Formula in an expression as you showed above. My issue is that I need manage the columns as a number and not a letter. Ranges have to be dynamic in columns. If I write: Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=SUM($I$5:$N$5)0" it works properly, but Selection.FormatConditions.Add Type:=xlExpression, FormulaR1C1:="=SUM(R5C9:R5C14)0" it doesn't. Can you give me any help on it? Thx |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Claus,
many thanks for your answer. Turning the Formula type from FormulaR1C1 to Formula! and using ".Address(0,0)" at least no error is returned. But now the CF is not effective (cells painted when the condition is true) even I can see the rule set on the CF Manager. |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hey Claus,
thanks for your help, now it works great. The point was the clause ".Address(0/1,0/1)" which lets me put the $'s wherever is needed. I fixed my issue by: ..FormatConditions.Add Type:=xlExpression, Formula1:="=SUMA(" & Cells(5, 9).Address(1, 1) & ":" & Cells(5, 14).Address(1, 1) & ")0" where columns now are available to be managed as numbers, thus variables. Regarding the language, my excel is Spanish. I had no need to use "FormulaLocal", what you see above is enough. Thanks again, Jordi |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Formatting & Macro | Excel Discussion (Misc queries) | |||
Conditional Formatting Macro | Excel Discussion (Misc queries) | |||
Conditional Formatting in a Macro | Excel Discussion (Misc queries) | |||
Conditional Formatting Macro | Excel Programming | |||
macro for conditional formatting | Excel Programming |