2016-10-04 82 views
0

我在VBA中有一個函數根據指定值設置單元格內部顏色的格式 - 負數和正數以及零。VBA單元有條件手動格式化 - 最佳做法

PositiveFillColor,NeutralFillColor和NegativeFillColor是將顏色讀入設置表單元格的全局長變量。

我主要關心的是宏的速度(對於中等數量的數據顯然似乎非常好)和工作簿大小(3,5 MB對於這個數據量似乎太多了)。

也許這是一個更好的做法,使用Excel條件格式與VBA?

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

有兩種方式試試這個,看看哪一個更快

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