LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Loop Unitl with timer

In your Run_Time_and_Sales() routine you need to be able to determine when to
loop back and pick up the first cell, and you need something to keep track of
where you are. You could set up a Static variable in the routine to keep up
with the "where" and the last row (so you can loop back).

Perhaps this code (which would do what you want) will give you some ideas of
how to deal with it.

Sub ShowAtOneSecondIntervals()
Const DelayInSeconds = 1
Dim rOffset As Long
Dim lastRow As Long
Dim neverEndFlag As Boolean
Dim stime As Long
Dim dcOne As Range
Dim dcTwo As Range
Dim baseCellOne As Range
Dim baseCellTwo As Range

'change worksheet name as required
Set dcOne = Worksheets("Sheet2").Range("D4")
Set dcTwo = Worksheets("Sheet2").Range("E4")
Set baseCellOne = Worksheets("Sheet2").Range("A1")
Set baseCellTwo = Worksheets("Sheet2").Range("B1")

lastRow = Range("A1").End(xlDown).Row
Do Until neverEndFlag ' never ends
dcOne.Value = baseCellOne.Offset(rOffset, 0).Value
dcTwo.Value = baseCellTwo.Offset(rOffset, 0).Value
stime = Timer
Do Until Timer stime + DelayInSeconds
DoEvents ' allow other things to happen
Loop
rOffset = rOffset + 1
If rOffset = lastRow Then
rOffset = 0
End If
Loop
End Sub


"blackbox via OfficeKB.com" wrote:

I have range of values in columns A & B which I would like to display 1 at a
time, at 1 second intervals in cells D4 and E4

I have some code but I'm not very good with loops.
How would I make this move from row 1 to row2 to row 3, etc.. at every 1
second re-fresh?

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1 ' 1 second
Public Const cRunWhat = "Run_Time_and_Sales"

Sub StartTimer()
If Range("F1") = "x" Then
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
Else: End
End If
End Sub

Sub Run_Time_and_Sales()

Dim LastPrint As Integer
Dim PrintTime As Integer

LastPrint = Range("A1").Value
PrinTime = Range("B1").Value

Range("D4") = LastPrint
Range("E4") = PrintTime


StartTimer

End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200706/1


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
help needed with timer / loop wendy_ia Excel Programming 0 June 17th 04 06:06 AM


All times are GMT +1. The time now is 08:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"