+ Reply to Thread
Results 1 to 4 of 4

Thread: Conditional Formatting

  1. #1
    Valued Forum Contributor
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    257

    Conditional Formatting

    Hi,

    I am using Excel 2007 and I have created several conditional formatting rules through the use of VBA.

    Using VBA:
    1) How can I delete a specific rule (not all of them)?

    2) How can I retrieve a list of all rules in a range?

    Regards,
    Elio Fernandes
    Attached Files Attached Files
    Last edited by efernandes67; 12-16-2010 at 04:02 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Conditional Formatting

    Hello Elio,

    Here is macro that will display the conditional formats for the active cell if they exist. The can be expanded to include other formats like the Font, Border, Pattern, etc.
    Sub ShowConditionalFormats()
    
      Dim CF As FormatCondition
      Dim I As Long
      Dim Msg As String
      Dim Rng As Range
        
        Set Rng = ActiveCell
      
        For I = 1 To Rng.FormatConditions.Count
            On Error Resume Next
              Set CF = Rng.FormatConditions(I)
              If Err = 0 Then GoSub GetConditions
            On Error GoTo 0
        Next I
        
    Exit Sub
    
    GetConditions:
    
          If CF.Type = 1 Then Msg = "Cell Value Is " Else Msg = "Formula Is "
          
          F1 = CF.Formula1
          
          On Error Resume Next
            F2 = CF.Formula2
            If Err <> 0 Then F2 = ""
          On Error GoTo 0
          
          Select Case CF.Operator
            Case 1: Msg = Msg & "Between " & F1 & " and " & F2
            Case 2: Msg = Msg & "Not Between " & F1 & " and " & F2
            Case 3: Msg = Msg & "Equal To " & F1
            Case 4: Msg = Msg & "Not Equal To " & F1
            Case 5: Msg = Msg & "Greater Than " & F1
            Case 6: Msg = Msg & "Less Than " & F1
            Case 7: Msg = Msg & "Greater Than Or Equal To " & F1
            Case 8: Msg = Msg & "Less Than Or Equal To " & F1
          End Select
          
          Msg = Msg & vbCrLf & "Format Color = " & CF.Interior.ColorIndex
        
          MsgBox Msg, vbOKOnly, "Condition " & I
          
    Return
    
    End Sub

    To delete a specific condition use its index number. The example below deletes condition 3 from the active cell.
        With ActiveCell.FormatConditions(3).Delete
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    257

    Re: Conditional Formatting

    Hello Ross,

    Thanks again for your help.

    I just attached a file because I am still having problems deleting specific "FormatConditions".

    The code in the module is:

    Sub delSpecificRules()
        Dim Rng As Range
        Dim r, nRules
        
        Set Rng = Range("B22:AJ44")
        
        nRules = Rng.FormatConditions.Count
        
        For r = 15 To nRules
            With Rng.FormatConditions(r).Delete
            End With
        Next
    End Sub
    I have created 19 rules, and I need to change my code, so that I can delete from the 15th untill the last one.

    Regards,
    Elio Fernandes

  4. #4
    Valued Forum Contributor
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    257

    Re: Conditional Formatting

    I was told that it is not possible do delete "range formatconditions" in Excel 2007, but it can be done in Excel2010.

    Elio

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0