Thread: timer issue
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Doug D.[_2_] Doug D.[_2_] is offline
external usenet poster
 
Posts: 4
Default timer issue

How would that look? I don't want to be trapped in a loop because I want to
be able to naviagte between lots of sheets while the timer is running.

"JLGWhiz" wrote:

Why not put the timer in the Worksheet_Calculate macro?

"Doug D." wrote:

I have data in sheet called "Safety Injection" that controls a 60 second
timer. This data comes from another sheet "Pressure" which I can change
manually. When I change the data in "Pressure" to start the timer, I get an
hourglass cursor preventing me from going to sheet "Safety Injection" to view
the timer. However, when I am simply on "Safety Injection" and manually force
the cell ("I22") controlling the timer to activate (remove the external link
and put number that I want), the timer works just fine. It's the switching
from sheet "Pressure" to "Safety Injection" while timer is running on "Safety
Injection" that is giving me problems.

Thanks in advance!

This is the code written in the "Safety Injection":

Option Explicit

Const WS_RANGE As String = "I22"

Private mPrev As Variant

Private Sub Worksheet_Calculate()

On Error GoTo ws_exit
Application.EnableEvents = False

If Me.Range(WS_RANGE).Value < mPrev Then
With Me.Range(WS_RANGE)
If .Value = 1 Then
nCount1 = 60
Call RunTimer1
ElseIf .Value = 0 Then
nCount1 = 0
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
mPrev = Me.Range(WS_RANGE).Value
End Sub


This is the code written in the standard code module:

Public nCount1 As Long

Public Sub RunTimer1()
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ThisWorkbook
Set aWS = aWB.Worksheets("Safety Injection")

If nCount1 = 0 Then

aWS.Range("W11") = nCount1
nCount1 = nCount1 - 1
Application.OnTime Now + TimeSerial(0, 0, 1), "RunTimer1"
End If
End Sub