PDA

View Full Version : Conditional Formatting - Change font



CodeNinja
10-04-2012, 08:51 AM
Hello fellow coders,
I am a little stumped with this one and thought someone might have some good input. A co-worker handed me a program that has a lot of computer generated macros that I am to take over. When I run this on my computer, it does not work, yet it works on his. It throws a 1004 "Application-Defined or Object-Defined Error" in the following (error occurs on line marked in Red):

' This section cleans up the Consultant Table to highlight the inspection
' count column with anything under 75 inspections.

ActiveWorkbook.refreshall
Sheets("Consultant Table").Select
Columns("B:B").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=75"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriori ty
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.Pattern = xlNone
.TintAndShade = 0
End With

I do not see anything wrong with this code that should throw that error. He got it by recording a macro. When I record a macro to do the same thing, I get the same code. Any ideas why this is throwing that error?

If I move that line to the interior area, it works fine (but obviously changes the interior color instead of the font color which I need it to do...) so it must have to do with the .font

Things I have tried that do not work include:
Changing color index to .color = rgb() or .color = #
Changing the selection to a range (declared variable, set variable, replaced etc)

snb
10-04-2012, 09:05 AM
This suffices.


ActiveWorkbook.refreshall
Sheets("Consultant Table").Columns(2).FormatConditions.Add(xlCellValue, xlLess, "=75").Font.colorindex=12

CodeNinja
10-04-2012, 09:15 AM
Xld,
Thanks for the reply, but oddly enough your code cut and paste (removing the old code) threw the same error. I'm stumped. Could it be something in my excel is corrupted? I'm grasping here ...