Stumped on Stopwatch Timer

rhettblaine

New Member
Joined
Oct 3, 2013
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hey guys,

A couple of months ago I found an extremely amazing VBA code for a stop watch that starts, pauses, and clears by clicking on 3 different cells instead of using buttons or shapes.

The company that I was working for was bought out and I (and no one else that I sent it to) was able to send a copy. I was able to save the code.

The only thing is that with this new company, it's not working as intended. The only way I can call the vba is by resorting to buttons. Even then, I can only activate the timer. I cannot pause/restart or clear.

Here is the code. I'm hoping that someone can let me know where to start. I cannot reference the site that I found this as the site is no longer active.

Also, I placed this under 'Modules' as well as in the Sheets. It does not work if I place it in the Sheets.


Code:
Public NextTime As Date
'This is located at the very top of the code module
    
Sub Call_Timer()
    NextTime = Now + TimeValue("00:00:01")
    ThisWorkbook.Sheets("Time").Range("D1").Value = ThisWorkbook.Sheets("Time").Range("D1").Value + 1 / 86400
    Application.OnTime NextTime, "Call_Timer"
End Sub
    
Sub UpdateTimer()
    If ActiveCell.Address = "$A$1" Then
        If NextTime = 0 Then Call_Timer
        
    ElseIf ActiveCell.Address = "$B$1" Then
        If NextTime > 0 Then Application.OnTime NextTime, "Call_Timer", Schedule:=False
        NextTime = 0
            
    ElseIf ActiveCell.Address = "$C$1" Then
        Range("D1").Value = 0
        
    End If
End Sub
Sub StatReset()
'
' StatReset Macro
'
'
    Range("D8").Select
    ActiveSheet.PivotTables("TimeStudyStats").PivotCache.Refresh
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi rhettblaine,

Place all your existing code in a Standard Code Module (note Sub StatReset is not needed for the timer).
Remove any of this code from any Sheet Code Modules.

In the Sheet Code for Sheet "Time" paste this code....

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   UpdateTimer
End Sub
 
Upvote 0
Thank you Jerry!

Sorry for the late reply.

Works great now. It's the small stuff that can get you.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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