gpt4 book ai didi

excel - 计色后表现不佳

转载 作者:行者123 更新时间:2023-12-02 01:58:30 26 4
gpt4 key购买 nike

在我的 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

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

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

我是不是做错了什么?有什么我可以做得更好来提高性能吗?

最佳答案

您可能在工作表中使用其他函数,并且每次重新计算 application.volatile 都会减慢您的代码速度。

删除 application.volatile 可能会解决您的问题。

关于excel - 计色后表现不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51926148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com