簡體   English   中英

VBA單元條件式格式與手動格式設置-最佳做法

[英]VBA cell conditional vs manual formatting - best practices

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

嘗試兩種方式,看看哪種更快

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM