Problem with DoEvents function

SkepMod

New Member
Joined
Oct 8, 2009
Messages
1
I am trying to create a simple file that will help me time a race I am organizing. I found the attached file online (I forget where), and have modified it over time.

I would like to simply be able to enter numbers into column B, and have the script record the time on the same row.

The recording function works fine when I use the button, but when I type into a cell on column B, the timer stops.

Option Explicit
Dim timelimit
Dim remaining
Dim stopped
Dim StartTimer
Dim BibNum


Public Sub startClock()

Dim start

start = Timer
Do While stopped = False
DoEvents
Worksheets("Timer").Range("G1").Value = Int((Timer - start + 0.5) / 60)
Worksheets("Timer").Range("H1").Value = Int((Timer - start + 0.5) / 60)
Worksheets("Timer").Range("J1").Value = (Timer - start) Mod 60
Worksheets("Timer").Range("k1").Value = (Timer - start + 0.5) - (Int(Timer - start + 0.5))

Loop

End Sub
Private Sub RecordButton_Click()
Record
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then Record

End Sub

Private Sub StartButton_Click()
startClock
End Sub

Private Sub StopButton_Click()
stopped = True
End Sub

Private Sub ResetButton_Click()

stopped = False
Worksheets("Timer").Range("G1").Value = 0
Worksheets("Timer").Range("H1").Value = 0
Worksheets("Timer").Range("J1").Value = 0
Worksheets("Timer").Range("k1").Value = 0

End Sub

Private Sub Record()
stopped = False

Dim time1 As Integer, time2 As Single, time3 As Integer, time4 As Double

Worksheets("Timer").Range("G1").Select
time1 = ActiveCell.Value
time2 = ActiveCell.Offset(0, 1).Value
time3 = ActiveCell.Offset(0, 3).Value
time4 = ActiveCell.Offset(0, 4).Value
Range("g65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = time1
ActiveCell.Offset(0, 1).Value = time2
ActiveCell.Offset(0, 3).Value = time3
ActiveCell.Offset(0, 4).Value = time4

Range("b65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select


End Sub​
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top