首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用VBA判断excel单元格是否应用了条件格式

如何使用VBA判断excel单元格是否应用了条件格式
EN

Stack Overflow用户
提问于 2015-01-29 09:15:00
回答 3查看 9.2K关注 0票数 4

这样做的目的是在视觉上区分正值、负值和无变化的值。

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

EN

回答 3

Stack Overflow用户

发布于 2015-01-29 09:28:12

查看Count是否为零:

代码语言:javascript
运行
复制
Sub dural()
    MsgBox ActiveCell.FormatConditions.Count
End Sub
票数 3
EN

Stack Overflow用户

发布于 2015-01-29 09:25:58

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

代码语言:javascript
运行
复制
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循环来检查特定范围内的所有条件。

票数 1
EN

Stack Overflow用户

发布于 2019-02-14 02:44:09

您可以使用Range.DisplayFormat检查是否应用了条件格式。将一些数据放入列A,然后使用下面的代码示例

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28205442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档