FormatCondition Operator

Dr. Demento

Well-known Member
Nov 2, 2010
I'm futzing around with Jeff Weir's Easy way to back up CF formats and I'm trying to create a list of CF that can then be read into a sub and applied on other workbooks. For the most part everything works out fine, but I'm having trouble with the FormatCondition.Operator Property. According to MSDN, it's supposed to "Returns a Long value that represents the operator for the conditional format." However, for the life of me I can't figure out what property to use to get the Operator value when reading the CF formats from a workbook.

I've tried object.Operator but I get RTE 1004 (application/object-defined error). I recognize there may not be any way to pull out the Operator, but never know . . .

Dim obj As Object
Dim fc As FormatCondition

    For Each obj In sht.Cells.FormatConditions
        strAddress = Replace(obj.AppliesTo.address, "$", vbNullString)  ' ~~ Removes "$"

        Select Case TypeName(obj)
          Case "FormatCondition"
            Set fc = obj
            tbl_addNewRow tbl
            tbl_addData tbl, Now, 1                                   ' Timestamp
            tbl_addData tbl,, 2                              ' sht name
            tbl_addData tbl, TypeName(fc), 3                          ' Variable type
            tbl_addData tbl, cfConditionType(fc.Type), 4              ' Type of CF
            t[B]bl_addData tbl, fc.Operator, 5                           ' Operator  <-- Hut the wheck?[/B]
            tbl_addData tbl, strAddress, 6                            ' address
            tbl_addData tbl, "'" & fc.Formula1, 7                     ' Formula of CF
            tbl_addData tbl, obj.StopIfTrue, 8                        ' bln - Stop if True
       End Select
     Next obj
The subs with tbl_ prefix have to do with putting the data in the table. They can be ignored.

I had to Dim cf as a generic Object instead of declaring as FormatCondition because DataBars screw things up.
' See When is a FormatCondition not a FormatCondition? | Excel Matters

Any thoughts?

Thanks y'all.

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Dr. Demento

Well-known Member
Nov 2, 2010
Bump? Does my question make sense? It does to me, but you know how well that works out :eek:


MrExcel MVP, Moderator
May 2, 2008
Office Version
365, 2019, 2016, 2010
Windows, MacOS
FormatCondition is the only one of the possible objects in the FormatConditions collection that actually has the Operator property, so you'd need to add a TypeName or TypeOf check to your code before trying to use it.

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics