2016-10-04 1 views
0

VBA에서 지정된 값 (음수 및 양수 및 0)을 기반으로 셀 내부 색상을 포맷하는 기능이 있습니다.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

두 가지로 이것을 시도하고 빠르게 어느 쪽 참조

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