如何判断一个Excel单元格是否使用VBA应用条件格式

我有一个应用条件格式的单元格的范围。

目的是在视觉上将这些价值观分为积极的,消极的和没有变化的。

如何使用VBA来检查单元格是否应用了条件格式(例如由于是负数而导致的单元格颜色)?

要使用VBA来检查单元格是否具有条件格式,请使用以下代码

 Dim check As Range Dim condition As FormatCondition Set check = ThisWorkbook.ActiveSheet.Cells.Range("A1") 'this is the cell I want to check Set condition = check.FormatConditions(1) 'this will grab the first conditional format condition. 'an autolist of methods and properties will pop up and 'you can see all the things you can check here 'insert the rest of your checking code here 

您可以使用上面的代码的一部分与每个循环检查特定范围内的所有条件。

看看计数是否为零:

 Sub dural() MsgBox ActiveCell.FormatConditions.Count End Sub