ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A Simple Timer (https://www.excelbanter.com/excel-programming/283087-simple-timer.html)

Jay Fincannon

A Simple Timer
 
I have a Worksheet_Change event that does different things depending
on which column is involved. I would like to set the current time
somewhere when I start entering data and again when I finish.
Entering 'End' triggers a sort routine. I just need to know the time
interval between starting and ending entries.

I know I could look at a clock both times, but that's not as much fun.

Chip Pearson[_2_]

A Simple Timer
 
Jay,

Try something like

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Worksheet_Change(ByVal Target As Range)
Dim StartTick As Long
Dim EndTick As Long
StartTick = GetTickCount()
'
' your code here
'
EndTick = GetTickCount()
MsgBox "Elapsed time (milliseconds): " & _
Format(EndTick - StartTick, "#,##0")
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jay Fincannon" wrote in message
...
I have a Worksheet_Change event that does different things depending
on which column is involved. I would like to set the current time
somewhere when I start entering data and again when I finish.
Entering 'End' triggers a sort routine. I just need to know the time
interval between starting and ending entries.

I know I could look at a clock both times, but that's not as much fun.




Jay Fincannon

A Simple Timer
 
That's exactamundo. How would I ever know about Lib "kernel32"() ?


On Thu, 20 Nov 2003 08:13:42 -0600, "Chip Pearson"
wrote:

Jay,

Try something like

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Worksheet_Change(ByVal Target As Range)
Dim StartTick As Long
Dim EndTick As Long
StartTick = GetTickCount()
'
' your code here
'
EndTick = GetTickCount()
MsgBox "Elapsed time (milliseconds): " & _
Format(EndTick - StartTick, "#,##0")
End Sub




All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com