Creating Countdown in Excel

psyclone

New Member
Joined
Oct 14, 2006
Messages
8
Greetings Excel Sages :)

Please Help... I'm trying to create a counter in excel with a fixed value of 15 minutes and every time that it reaches zero, it will put an incremental integer on a specified cell then it should loop back to start the counter. i i also wanted to put a start button and end button.

i got this from another thread but this one displays a message instead

Sub Countup()
Dim CountDown As Date
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Realcount"
End Sub

Sub Realcount()
Dim count As Range
Set count = [a1]
count.Value = count.Value - TimeSerial(0, 0, 1)
If count <= 0 Then
MsgBox "Countdown complete."
Exit Sub
End If
Call Countup
End Sub
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
Sub Countup()  Dim CountDown As Date
  CountDown = Now + TimeValue("00:00:01")
  Application.OnTime CountDown, "Realcount"
End Sub


Sub Realcount()
  Dim count As Range


  Set count = [A1]
  Sheets("Sheet1").Range("A1").NumberFormat = "mm:ss"
  count.Value = count.Value - TimeSerial(0, 0, 1)
  If count <= 0 Then
    Sheets("Sheet1").Range("B1").Value = Sheets("Sheet1").Range("B1").Value + 1
    count.Value = TimeSerial(0, 15, 0)
  End If
  Call Countup
End Sub
 
Upvote 0
Code:
Sub Countup()  Dim CountDown As Date
  CountDown = Now + TimeValue("00:00:01")
  Application.OnTime CountDown, "Realcount"
End Sub


Sub Realcount()
  Dim count As Range


  Set count = [A1]
  Sheets("Sheet1").Range("A1").NumberFormat = "mm:ss"
  count.Value = count.Value - TimeSerial(0, 0, 1)
  If count <= 0 Then
    Sheets("Sheet1").Range("B1").Value = Sheets("Sheet1").Range("B1").Value + 1
    count.Value = TimeSerial(0, 15, 0)
  End If
  Call Countup
End Sub

Thank you for the quick reply. However, I encountered an error "Type Mismatch" and this is highlighted > count.Value = count.Value - TimeSerial(0, 0, 1)
 
Upvote 0
Runs Just fine. I'm using excel 2010

here's a little revision

Code:
Sub Countup()  Dim CountDown As Date
  CountDown = Now + TimeValue("00:00:01")
  Application.OnTime CountDown, "Realcount"
End Sub


Sub Realcount()
  With Sheets("Sheet1")
    .Range("A1").NumberFormat = "mm:ss"
    .Range("A1").Value = .Range("A1").Value - TimeSerial(0, 0, 1)
  If .Range("A1").Value <= 0 Then
    .Range("B1").Value = .Range("B1").Value + 1
    .Range("A1").Value = TimeSerial(0, 15, 0)
  End If
  End With
  Call Countup
End Sub
 
Last edited:
Upvote 0
Runs Just fine. I'm using excel 2010

here's a little revision

Code:
Sub Countup()  Dim CountDown As Date
  CountDown = Now + TimeValue("00:00:01")
  Application.OnTime CountDown, "Realcount"
End Sub


Sub Realcount()
  With Sheets("Sheet1")
    .Range("A1").NumberFormat = "mm:ss"
    .Range("A1").Value = .Range("A1").Value - TimeSerial(0, 0, 1)
  If .Range("A1").Value <= 0 Then
    .Range("B1").Value = .Range("B1").Value + 1
    .Range("A1").Value = TimeSerial(0, 15, 0)
  End If
  End With
  Call Countup
End Sub

thanks ttdk1. probably the reason why i got the error is when i switch to another excel file while the macro is running since i did not select "this workbook" when i run the macro... silly me, sorry.

now it's working fine using the simple code. thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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