这样做的目的是在视觉上区分正值、负值和无变化的值。
如何使用VBA检查单元格是否应用了条件格式(例如,由于为负数而导致的单元格颜色)?
发布于 2015-01-29 09:28:12
查看Count是否为零:
Sub dural()
MsgBox ActiveCell.FormatConditions.Count
End Sub
发布于 2015-01-29 09:25:58
要使用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
您可以使用上述代码的一部分和一个for each循环来检查特定范围内的所有条件。
发布于 2019-02-14 02:44:09
您可以使用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
https://stackoverflow.com/questions/28205442
复制相似问题