【发布时间】:2017-03-03 04:07:38
【问题描述】:
只有当单元格具有特定公式时,有没有办法删除单元格上的条件格式?
我现在有
Cells(r, 4).Select
With Selection
.FormatConditions.Item(1).Delete
End With
但我只希望它删除公式中的格式
="=ISBLANK(A19)=TRUE"
有人知道这是否可能吗?
【问题讨论】:
只有当单元格具有特定公式时,有没有办法删除单元格上的条件格式?
我现在有
Cells(r, 4).Select
With Selection
.FormatConditions.Item(1).Delete
End With
但我只希望它删除公式中的格式
="=ISBLANK(A19)=TRUE"
有人知道这是否可能吗?
【问题讨论】:
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
【讨论】:
ClearFormulaCF