Consulting

Results 1 to 3 of 3

Thread: Conditional Formatting - Change font

  1. #1
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location

    Conditional Formatting - Change font

    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):

    [vba] ' 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
    [/vba]
    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)

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    This suffices.

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

  3. #3
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    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 ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •