【Excel VBA】Timer

【Excel VBA】Timer
Timer()函数返回自凌晨00:00起的秒数和毫秒数。

Private Sub Constant_demo_Click()
   msgbox("Time is : " & Now())
   msgbox("Timer is: " & Timer())
End Sub

【Excel VBA】Timer
【Excel VBA】Timer

例子

Sub Counter_Looping_for_Timer()
'for tab Find (for Timer testing)

    Dim r As Long
    Dim i As Byte
    i = 3
    Dim Start
    
    ' 记录开始的时间
    Start = VBA.Timer
    Range("D3:D6").ClearContents
    'this part is hardcoded for the purpose of testing the Timer Function
    For r = 8 To 200000
        If UCase(Range("A" & r).Value) = UCase(Range("B3").Value) Then
            Range("D" & i).Value = Range("E" & r).Value
            i = i + 1
        End If
    Next r
    
    ' 用debug输出运算时间
    Debug.Print Round(Timer - Start, 3)
    
End Sub