Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default loop problem

Hiya

I have a looping sub that takes 5 cells and every 0.2 seconds adds to their
values, dealing with one at each successive 0.2 second interval , so that by
the end of each second every cell has been visited and increased by the
macro once. In other words at 0.2 seconds A1 is increased, at 0.4 seconds B1
is increased, 0.6 seconds C1 is increased 0.8 seconds D1 is increased and
then at 1 second E1 is increased. And then it all loops.

The problem I have is that I want to increase the cell values by the value
of just one each time. By using the = instruction it increases each cell by
many hundreds on each loop cycle (except for the last one in the series.)
However if I just use = instead, the system ignores the instruction
altogether - it doesn't seem sensitive enough to register.

Any solutions involving lots of do loops disrupt the timer function
altogether, which is very vulnerable to any system resource reallocations.

Does anyone see a simple elegant solution that doesn't require heavier
processing? Many thanks.

Sub count()
Range("A1") = 0
Range("B1") = 0
Range("C1") = 0
Range("D1") = 0
Range("E1") = 0

tim1 = Timer 'sets the time the process started
Do
tim2 = Timer 'sets current time
diff = tim2 - tim1 'derives the number of seconds since process started,
refreshing on every loop

If diff = 1 Then
Range("e1") = Range("e1") + 1
tim1 = Timer 'restarts process by resetting number of seconds since
process started to zero

ElseIf diff = 0.8 Then
Range("d1") = Range("d1") + 1

ElseIf diff = 0.6 Then
Range("c1") = Range("C1") + 1

ElseIf diff = 0.4 Then
Range("b1") = Range("b1") + 1

ElseIf diff = 0.2 Then
Range("a1") = Range("a1") + 1

End If

Loop

End Sub


 
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
Does loop function cause this problem? Eric Excel Worksheet Functions 3 July 1st 07 01:40 PM
do..loop Anna Excel Discussion (Misc queries) 6 June 20th 07 01:10 PM
while loop Arun Kumar Saha Excel Worksheet Functions 2 June 19th 07 01:31 PM
Help with Do...Loop Noemi Excel Discussion (Misc queries) 1 December 7th 05 12:59 AM
Find and Copy loop problem BillyJ Excel Discussion (Misc queries) 3 November 2nd 05 07:16 PM


All times are GMT +1. The time now is 09:09 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"