Triggering Macro to Run Once When Countdown Timer is Within Range

rob51852

Board Regular
Joined
Jun 27, 2016
Messages
190
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have put together the following macro to run when a countdown timer is between a certain range. I only want it to run the Capture macro once.

Is this a good way to code it or can anyone see any potential issues?

VBA Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
If Range("AG5") < 12650 And Range("AG5") > 12640 Then Call Capture
Application.EnableEvents = True
End Sub

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,
try this update to your code & see if does what you want

VBA Code:
Private Sub Worksheet_Calculate()
    Application.EnableEvents = False
    
    With Range("AG5")
        If Val(.ID) = 0 Then
            If .Value < 12650 And .Value > 12640 Then Call Capture
        Else
            .ID = xlOff
        End If
    End With
    
    Application.EnableEvents = True
End Sub

Solution should re-set itself each time workbook is closed.

Dave
 
Upvote 0
@dmt32 - clever use of Range ID property (y)
- I would not have thought of that

But it does not trigger correctly for me
Can I suggest this modification
VBA Code:
Private Sub Worksheet_Calculate()
    Application.EnableEvents = False
    With Range("AG5")
        If Val(.ID) <> xlOff Then
            If .Value < 12650 And .Value > 12640 Then
                .ID = xlOff
                Call Capture
            End If
        End If
    End With
    Application.EnableEvents = True
End Sub
 
Upvote 0
@dmt32 - clever use of Range ID property (y)
- I would not have thought of that

But it does not trigger correctly for me
Can I suggest this modification

Most of the offerings I post are untested & welcome any helpful corrections
I have used ID of Range as "Tag" in many situations like this - can be very handy but not sure if OP wanted the run once to be permanent as ID property as you know, does not retain its value.

Dave
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,052
Latest member
Fuddy_Duddy

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