小编Psy*_*sun的帖子

颜色计数后性能不佳

在将此代码实现到Excel列表中以计算在设置范围内没有颜色的填充单元格后,我遇到了性能不佳的问题:

Function CountCcolor(range_data As Range, criteria As Range) As Long
    Dim datax As Range
    Dim xcolor As Long
    xcolor = criteria.Interior.ColorIndex
    For Each datax In range_data
        If datax.Interior.ColorIndex = xcolor And Not datax.Value = vbNullString Then
           CountCcolor = CountCcolor + 1
        End If
    Next datax
End Function
Run Code Online (Sandbox Code Playgroud)

我也使用这个来计算设定范围内同一页面上的黄色和红色单元格,但它不会像上面那样降低性能:

Function Farbsumme(Bereich As Range, Farbe As Integer)
    Dim Zelle As Range
    Application.Volatile
    For Each Zelle In Bereich
        If Zelle.Interior.ColorIndex = Farbe Then
            Farbsumme = Farbsumme + 1
        End If
    Next
End Function …
Run Code Online (Sandbox Code Playgroud)

excel excel-vba excel-formula

7
推荐指数
1
解决办法
103
查看次数

标签 统计

excel ×1

excel-formula ×1

excel-vba ×1