【问题标题】:Excel VBA Conditional Formatting Remove FormulaExcel VBA 条件格式删除公式
【发布时间】:2017-03-03 04:07:38
【问题描述】:

只有当单元格具有特定公式时,有没有办法删除单元格上的条件格式?

我现在有

Cells(r, 4).Select      
With Selection
.FormatConditions.Item(1).Delete
End With

但我只希望它删除公式中的格式

="=ISBLANK(A19)=TRUE"

有人知道这是否可能吗?

【问题讨论】:

    标签: vba excel


    【解决方案1】:
    Sub Tester()
    
        ClearFormulaCF Range("A1:A5"), "=ISBLANK(A19)=TRUE"
    
    End Sub
    
    'Remove any CF rule from cells in rng where the CF formula
    '   matches the one provided
    Sub ClearFormulaCF(rng As Range, sFormula As String)
        Dim rngCF As Range, c As Range, fc As FormatCondition
    
        On Error Resume Next
        'any cells with CF?
        Set rngCF = rng.SpecialCells(xlCellTypeAllFormatConditions)
        On Error GoTo 0
        If rngCF Is Nothing Then Exit Sub 'no CF found
    
        For Each c In rngCF.Cells
            For Each fc In c.FormatConditions
                If fc.Formula1 = sFormula Then
                    fc.Delete
                    Exit For
                End If
            Next fc
        Next c
    End Sub
    

    【讨论】:

    • 嘿,谢谢蒂姆,很抱歉没有早点回复,我正忙于其他事情。我能问个问题吗?这里的操作顺序是什么?如果我降落在一个单元格上,我是否先调用 Sub Tester,然后调用 Sub ClearFormulaCF?还是之前调用过 Tester?
    • "Tester" 只是您实际代码的替代品,用于演示您将如何使用 ClearFormulaCF
    猜你喜欢
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 2018-05-10
    相关资源
    最近更新 更多