excel - 有没有更快的方法在 excel vba 中循环使用 ColorCounter?
问题描述
我有一个可以工作的 lColorCounter 代码,但速度很慢。有没有更快的方法来循环使用 lColorCounter?
Dim rng As Range
Dim lColorCounter As Long
Dim rngCell As Range
Set rng = Sheets("MASTER LINE LIST").Range("C2:Z2000")
lColorCounter = 0
For Each rngCell In rng
'Checking BLUE color
If Cells(rngCell.Row, rngCell.Column).DisplayFormat.Interior.Color = RGB(0, 176, 240) Then
lColorCounter = lColorCounter + 1
End If
Next
Sheets("Status").Range("C5") = lColorCounter
lColorCounter = 0
For Each rngCell In rng
'Checking Yellor color
If Cells(rngCell.Row, rngCell.Column).DisplayFormat.Interior.Color = RGB(255, 255, 0) Then
lColorCounter = lColorCounter + 1
End If
Next
Sheets("Status").Range("B5") = lColorCounter
解决方案
循环一次:
Dim rng As Range
Dim bColorCounter As Long
Dim yColorCounter As Long
Dim rngCell As Range
Set rng = Worksheets("MASTER LINE LIST").Range("C2:Z2000")
bColorCounter = 0
yColorCounter = 0
For Each rngCell In rng
'Checking BLUE color
If rngCell.DisplayFormat.Interior.Color = RGB(0, 176, 240) Then
bColorCounter = bColorCounter + 1
ElseIf rngCell.DisplayFormat.Interior.Color = RGB(255, 255, 0) Then
yColorCounter = yColorCounter + 1
End If
Next
Sheets("Status").Range("C5") = bColorCounter
Sheets("Status").Range("B5") = yColorCounter
推荐阅读
- go - 如何在本地计算机中获取 Google Cloud api(firestore)的权限
- bash - 在什么情况下文件通配在 bash 中不起作用?
- c# - 如何向 datagridview 有界表单 DataTable 添加更多列?
- python - 如何将数据传递给 jinja 模板
- git - 如何在`git rebase --continue`期间跳过合并
- python-3.x - 使用 Beautiful Soup 删除元素的第一个实例
- mysql - ERROR 2005 (HY000): Unknown MySQL server host '[35.232.51.216]' (0) in google cloud SQL client
- javascript - 为什么请求帖子没有运行
- python - Twine 挂起而不提示输入密码
- excel - Excel INDEX MATCH 多列数据集转换为行列数据集