Results 1 to 20 of 33

Thread: Delete all conditional formatting and coloring conditional on specific rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,877
    Location
    Some things for you to think about

    Lot of redundant code removed, no need to .Select and both rows were getting the same CF

    I rearranged the CF tests in a 'get out' order

    I like .Color and .ColorIndex instead of Pattern, Tint and Shade so I changed since I was more familiar with them. Put them back if you prefer of course

    Don't think you needed the "=LEN(TRIM(C3))>0" so I left it out

    I think it's important to use .FormatConditions.Count


    Option Explicit         '   <<<<<<<<<<<<<<<<<<<
    
    
    Sub test2()
        
        With Worksheets("Blagoevgrad total")     '   <<<<<<<<<< or specific sheet
        
            .Cells.FormatConditions.Delete
        
            With Application.Union(.Range("C4:N4"), .Range("C8:N8"))
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=$A$4+200"
                .FormatConditions(.FormatConditions.Count).Interior.Color = vbRed
                .FormatConditions(.FormatConditions.Count).StopIfTrue = True
                
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=$A$4+150"
                .FormatConditions(.FormatConditions.Count).Interior.ColorIndex = 15
                .FormatConditions(.FormatConditions.Count).StopIfTrue = True
                
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=$A$4+100"
                .FormatConditions(.FormatConditions.Count).Interior.ColorIndex = 24
                .FormatConditions(.FormatConditions.Count).StopIfTrue = True
            
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=$A$4+50"
                .FormatConditions(.FormatConditions.Count).Interior.ColorIndex = 20
                .FormatConditions(.FormatConditions.Count).StopIfTrue = True
            End With
            
            .Select
            .Range("C2").Select
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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