Results 1 to 1 of 1

get cell interior color of active conditional format met - excel 2007

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    get cell interior color of active conditional format met - excel 2007

    I need to be able to get the cell interior color of the current conditional format met.
    So I can easily test if my range of cells are in a particular state based on the CF colour (eg Red is bad)

    I have trialed an approach by Chip Pearson & Bob Phillips but without sucess in 2007.

    '---------------------------------------------------------------------
    Public Function CFColorindex(rng As Range)
    '---------------------------------------------------------------------
    Dim oFC As FormatCondition
    Dim sF1 As String
    Dim iRow As Long
    Dim iColumn As Long
    
       Set rng = rng(1, 1)
       If rng.FormatConditions.Count > 0 Then
          For Each oFC In rng.FormatConditions
             If oFC.Type = xlCellValue Then
                Select Case oFC.Operator
                   Case xlEqual
                      CFColorindex = rng.Value = oFC.Formula1
                   Case xlNotEqual
                      CFColorindex = rng.Value <> oFC.Formula1
                   Case xlGreater
                      CFColorindex = rng.Value > oFC.Formula1
                   Case xlGreaterEqual
                      CFColorindex = rng.Value >= oFC.Formula1
                   Case xlLess
                      CFColorindex = rng.Value < oFC.Formula1
                   Case xlLessEqual
                      CFColorindex = rng.Value <= oFC.Formula1
                   Case xlBetween
                      CFColorindex = (rng.Value >= oFC.Formula1 And _
                                 rng.Value <= oFC.Formula2)
                   Case xlNotBetween
                      CFColorindex = (rng.Value < oFC.Formula1 Or _
                                 rng.Value > oFC.Formula2)
                End Select
             Else
                 're-adjust the formula back to the formula that applies
                 'to the cell as relative formulae adjust to the activecell
                With Application
                   iRow = rng.Row
                   iColumn = rng.Column
                   sF1 = .Substitute(oFC.Formula1, "ROW()", iRow)
                   sF1 = .Substitute(sF1, "COLUMN()", iColumn)
                   sF1 = .ConvertFormula(sF1, xlA1, xlR1C1)
                   sF1 = .ConvertFormula(sF1, xlR1C1, xlA1, , rng)
                End With
                CFColorindex = rng.Parent.Evaluate(sF1)
             End If
    
             If CFColorindex Then
                If Not IsNull(oFC.Interior.Colorindex) Then
                   CFColorindex = oFC.Interior.Colorindex
                   Exit Function
                End If
             End If
         Next oFC
       End If 'rng.FormatConditions.Count > 0
    
    End Function
    I think Bob is on the right track with the substitution and conversion of expression formula, but formula returned to evaluate is not correct.

    I have attached a simple CF example file
    Refer cell A2. when evaluating the CF it converts formula (rule applied to range A1:A3) from "=A1=1" to "XFD1=1", where it should actually be "A2=1"

    I would appreciate help to resolve this issue.
    Attached Files Attached Files

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.6.0 RC 1