PDA

View Full Version : Solved: determine how long user was on a sheet



slang
01-04-2013, 06:47 AM
Hello Excel gods:bow:

I have a survey the user inputs data into which we would like to know how long the user took to complete it.
The survey is on a hidden sheet and invoked through code and can only be exited by completing the required fields and choosing a complete button.

So my logic is that if the user actually completed the survey correctly it would take longer than just answering yes to everything just to get it out of the way.:devil2:

So I was thinking about code in the worksheetactivate event that would set the start time,
Static StrtTime As Date
Static Counter As Date
StrtTime = Now

and another in the complete button code,
Counter = Now - StrtTime
that determined the elapsed time spent on the sheet.:dunno

First time with static variables:)
There is probably a better way....
Thanks all.

Kenneth Hobs
01-04-2013, 12:30 PM
I would use Timer. Set t1 as a Private double type variable so that it can be retrieved.

e.g.Sub FillARange()
Dim r As Range, bRange As Range, t1 As Double
Cells.ClearContents
t1 = Timer
'SpeedOn
[A1] = "ColA"
[B1] = "ColB"
[C1] = "ColC"
Set bRange = Range("A2:C1000")
For Each r In bRange
If r.Column = 1 And r.Row Mod 2 = 0 Then
r.Value = "Delete"
Else: r.formula = "=Row()*Column()"
End If
Next r
'SpeedOff
MsgBox "Added " & bRange.Rows.Count & " rows and " & bRange.Count & " cells." & _
vbCrLf & "It took " & CStr(Timer - t1) & " seconds."
End Sub

snb
01-04-2013, 03:19 PM
or to register in minutes:


Private Sub Workbook_Open()
ThisWorkbook.CustomDocumentProperties.Add "start", False, msoPropertyTypeDate, Now
End Sub

Private Sub commandbutton1_Click()
MsgBox DateDiff("n", ThisWorkbook.CustomDocumentProperties("start").Value, Now)
End Sub

slang
01-09-2013, 10:37 AM
I would use Timer. Set t1 as a Private double type variable so that it can be retrieved.

e.g.Sub FillARange()
Dim r As Range, bRange As Range, t1 As Double
Cells.ClearContents
t1 = Timer
'SpeedOn
[A1] = "ColA"
[B1] = "ColB"
[C1] = "ColC"
Set bRange = Range("A2:C1000")
For Each r In bRange
If r.Column = 1 And r.Row Mod 2 = 0 Then
r.Value = "Delete"
Else: r.formula = "=Row()*Column()"
End If
Next r
'SpeedOff
MsgBox "Added " & bRange.Rows.Count & " rows and " & bRange.Count & " cells." & _
vbCrLf & "It took " & CStr(Timer - t1) & " seconds."
End Sub

Excellent!
Thanks so much, worked perfect....:bow: