我有一系列应用了条件格式的单元格。
目的是通过视觉方式区分具有正数、负数和无变化值的单元格。
如何使用VBA检查这些单元格是否应用了条件格式(例如由于是负数而导致单元格颜色)?
我有一系列应用了条件格式的单元格。
目的是通过视觉方式区分具有正数、负数和无变化值的单元格。
如何使用VBA检查这些单元格是否应用了条件格式(例如由于是负数而导致单元格颜色)?
检查Count是否为零:
Sub dural()
MsgBox ActiveCell.FormatConditions.Count
End Sub
您可以使用Range.DisplayFormat来检查是否应用了条件格式。 将一些数据放入A列,然后使用以下代码示例:
Private Sub TestConditionalFormat()
Range("A:A").FormatConditions.AddUniqueValues
Range("A:A").FormatConditions(1).DupeUnique = xlDuplicate
Range("A:A").FormatConditions(1).Interior.Color = 13551615
Dim rCell As Range
Dim i As Long
For Each rCell In Range(Range("A1"), Range("A1").End(xlDown))
If rCell.DisplayFormat.Interior.Color = 13551615 Then
i = i + 1
End If
Next
MsgBox i & " :Cells Highlights for Duplicates."
End Sub
使用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