Public activeRow As Variant
Public activeCol As Variant
'http::/www.mrexcel.com/archive/VBA/2357.html
Dim CountDown As Date
'http::/www.mrexcel.com/archive/VBA/2357.html
Private Sub Timer()
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Reset"
End Sub
'http::/www.mrexcel.com/archive/VBA/2357.html
Private Sub Reset()
Dim count As Range
Set count = [J5] ' J5 contains the number of seconds for the countdown.
count.Value = count.Value - 1
If count <= 0 Then
MsgBox "Countdown complete."
Exit Sub
End If
Call Timer
End Sub
'http::/www.mrexcel.com/archive/VBA/2357.html
Private Sub DisableTimer()
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False
End Sub
Private Sub StoreActiveCell()
activeRow = ActiveCell.row
activeCol = ActiveCell.Column
End Sub
Private Sub RestoreActiveCell()
Cells(activeRow, activeCol).Select
End Sub
Public Sub RunTimer()
StoreActiveCell
Range("J5").Select
'http://www.mrexcel.com/forum/showthread.php?p=2345954&posted=1#post2345954
'This pulls the first element from the splitting of the text on the pressed button.
'Split(ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text, " ")(0)
'So if a button with text of "60 Second Timer" is pressed "60" is captured.
ActiveCell.FormulaR1C1 = _
Split(ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text, " ")(0)
Call Timer
RestoreActiveCell
End Sub