ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   timer issue (https://www.excelbanter.com/excel-programming/413208-timer-issue.html)

Doug D.

timer issue
 
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

[email protected]

timer issue
 
Hi
you need to insert
aWB.Activate

before the timer starts.
regards
Paul

On Jun 27, 1:41*pm, Doug D. <Doug
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



Doug D.[_2_]

timer issue
 
In which part of the code do I put:

aWB.Activate

" wrote:

Hi
you need to insert
aWB.Activate

before the timer starts.
regards
Paul

On Jun 27, 1:41 pm, Doug D. <Doug
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




JLGWhiz

timer issue
 
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


Doug D.[_2_]

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


Doug D.[_2_]

timer issue
 
I can email instructions and excel file (1.1 MB) to you if that would help to
get a better idea of what's going on.

"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



All times are GMT +1. The time now is 10:25 AM.

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