FormatCondition Operator

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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 . . .

Code:
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, sht.name, 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.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Bump? Does my question make sense? It does to me, but you know how well that works out :eek:
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top