ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Switching sheets while timer running (https://www.excelbanter.com/excel-programming/413471-switching-sheets-while-timer-running.html)

Doug D.[_2_]

Switching sheets while timer running
 
This is the code written in the sheet called "Safety Injection":

Option Explicit

Const WS_RANGE As String = "Q35"

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
nCount = 15
Call RunTimer
ElseIf .Value = 0 Then
nCount = 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 nCount As Long

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

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

If nCount = 0 Then

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

Timer is malfunctioning when I try to switch between sheets. I have data
that goes into sheet called "Pressure". This data causes "Q35" on "Safety
Injection" to become either a 1 or a 0. When I manually change the data in
the "Pressure Sheet", timer on "Safety Injection" should starting counting
down from 15 to 0. Timer sometimes doesn't run or it sometimes it starts
counting down by 2's.

Help please...Thanks


All times are GMT +1. The time now is 05:17 PM.

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