2016-10-21 323 views
0

只有在具有特定公式的情況下,是否可以刪除單元格的條件格式?Excel VBA條件格式刪除公式

現在我有

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

但我只希望它刪除格式如果公式

="=ISBLANK(A19)=TRUE" 

有誰知道,如果這是一個可能性?

回答

0
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 
+0

嘿,謝謝蒂姆,抱歉我以前沒有回覆,我忙於其他事情。我能問個問題嗎?這裏的操作順序是什麼?如果我着陸在一個單元格上,我可以調用Sub Tester然後Sub ClearFormulaCF?或者測試人員之前被調用過? –

+0

「測試人員」僅代表您的實際代碼的替身,以演示如何使用「ClearFormulaCF」 –