• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 47
  • Last Modified:

CAlculate the time elapsed

I wrote the below code but getting an error .
I want to get elapsed time .
Facing an error while subrating time i.e. final time .

Private Sub CommandButton1_Click()
Range("D2").End(xlDown).Offset(1, 0).Select
Selection.Value = Now()
Starttime = Format(Now(), "hh:mm:ss")
End Sub

Private Sub CommandButton2_Click()
 Dim finaltime As Date
 Dim time1, time2 As Date
 Range("D4").Value = time1
 Final = Format(Now(), "hh:mm:ss")
finaltime = Final - Starttime
 Range("F2").End(xlDown).Offset(1, 0).Select = finaltime
End Sub
Ramesh sharma
Ramesh sharma
1 Solution
Wayne Taylor (webtubbs)Commented:
Don't use the Format function as it converts the times to a String.

Make sure StartTime and finaltime are declared as Date, and just set each to Now in the Click events...
Starttime = Now

Final = Now

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now