我在VBA中有一个函数可以根据指定的值(负数和正数以及零)格式化单元格内部颜色。
PositiveFillColor,NeutralFillColor和NegativeFillColor是读取放入设置表单元格的颜色的全局长变量。
我主要担心的是宏的速度(对于中等数量的数据显然看起来非常好)和工作簿大小(对于这个数据量,3,5 MB似乎太多了)。
在VBA中使用Excel条件格式可能是一种更好的做法吗?
Public Function FillColorByValue(ByVal RefNumber As Double) As Long
Dim FillColor As Long
If RefCellValue > 0 Then
FillColor = PositiveFillColor
ElseIf RefCellValue = 0 Then
FillColor = NeutralFillColor
ElseIf RefCellValue < 0 Then
FillColor = NegativeFillColor
End If
FillColorByValue = FillColor
End Function
答案 0 :(得分:0)
尝试两种方式,看看哪一种更快
sub thetimingstuff()
Dim StartTime As Double
Dim SecondsElapsed As Double
StartTime = Timer
'your code goes here
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
end sub