excel - 获取条件格式的单元格(DupeUnique = xlDuplicate)
问题描述
我使用以下方法突出显示选择中的所有重复单元格:
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
现在我不仅想突出显示这些单元格,而且我想获得一个包含所有受影响单元格的数组。我尝试遍历我的选择并检查 Interior 属性,但这需要很长时间。我正在寻找更快的方法。
解决方案
一个函数,返回 Excel 选择中所有值的列表(集合),对应于这个条件:
If myCell.DisplayFormat.Interior.Color = myColor Then
会很有用:
Sub TestMe()
'...OP Code
.TintAndShade = 0
End With
Dim unique As Collection
Set unique = ResultList(Selection)
If unique.Count > 1 Then Debug.Print unique.Item(2)
End Sub
Public Function ResultList(selectedRange As Range, _
Optional myColor As Long = 13551615) As Collection
Dim myCell As Range
Dim myResultList As New Collection
For Each myCell In selectedRange
If myCell.DisplayFormat.Interior.Color = myColor Then
myResultList.Add myCell.Value2
End If
Next myCell
Set ResultList = myResultList
End Function
因此,Selection
可以避免使用它,并且可以进一步使用它。
推荐阅读
- magento2 - 覆盖magento2中system.xml中的注释
- ios - 在 iOS 项目中使用 Google Identity-Aware Proxy 和 Google SignIn
- css - 为什么 Bootstrap 4 中的 img-fluid 类没有在他们的 div 中调整我的图像大小?
- python - 没有名为 pool.tensor 的模块
- jmeter - 获取 java.net.ConnectException:连接超时:jmeter 中的连接响应
- python-3.x - 在熊猫中给出卷号时如何获取名称
- javascript - 是否可以防止修改对象的特定键的值?
- vb.net - 如何解决水晶报表公式编辑器中的错误
- c - 使用 VS 2013 编译器将 .a 文件与 CMake 链接
- javascript - jQuery img 循环