FormatCondition Operator
Results 1 to 3 of 3

Thread: FormatCondition Operator
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular Dr. Demento's Avatar
    Join Date
    Nov 2010
    Location
    Skipping stones off Charon's Ferry
    Posts
    541
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default FormatCondition Operator

    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
                tbl_addData tbl, fc.Operator, 5                           ' Operator  <-- Hut the wheck?
                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.

  2. #2
    Board Regular Dr. Demento's Avatar
    Join Date
    Nov 2010
    Location
    Skipping stones off Charon's Ferry
    Posts
    541
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: FormatCondition Operator

    Bump? Does my question make sense? It does to me, but you know how well that works out

  3. #3
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,661
    Post Thanks / Like
    Mentioned
    47 Post(s)
    Tagged
    6 Thread(s)

    Default Re: FormatCondition Operator

    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.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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