Dim person, needs help

W

Wooders

Please help

All I want to do is write (record and edit) a macro in
excel that will repeat the calculate (F9) function every 5
seconds for a set period i.e. an hour.

I am really sure this is very easy if you know how. This
is for use in a small countdown program that at the moment
I manually have to hit the F9 key.

Can someone guide me, thanks in advance.

wooders
 
L

Lance

Sub calc_it()
Application.Calculate
Application.OnTime Now + TimeValue("00:00:05"), "calc_it"
End Sub

use tools|macro run to start it and then it will continue
on its own.

LAnce
 
R

Robin Hammond

Wooders,

This should do it. If you put two buttons on a sheet to run the Initiate and
StopIt routines, you can start and stop the process.

Option Explicit
Private dNextTime As Double
Private dEndTime As Double

Sub Initiate()
dEndTime = Now + TimeValue("01:00:00")
Recalc
End Sub

Sub Recalc()
dNextTime = Now + TimeValue("00:00:05")
If dNextTime < dEndTime Then Application.OnTime dNextTime, "Recalc"
Application.Calculate
End Sub

Sub StopIt()
Application.OnTime dNextTime, "Recalc", , False
End Sub

Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in
 
D

Dave Woodley

LAnce

Thank you very much for your help. Although this is a very simple file
(my excel authoring) it has brought a great deal of pleasure to my
better half, who has this running showing days, hours etc remaining
until we go on holiday.

Again many thanks

Wooders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top