Simple Timer Help

Resz7

New Member
Joined
Aug 4, 2014
Messages
12
Hi everyone,
I'm new to timers so I could use help. Basically this timer runs every second and calls "main" sub. How can I increase "i" by 1 every time it runs? I would like it to read each cell in Column A every second. Thanks!

Code:
Sub Timer()

Application.OnTime Now + TimeValue("00:00:01"), "Main"
End Sub


Sub Main()
Dim i As Long
Dim x As String
i = 1

x = Worksheets("Sheet1").Cells(i, 1).Value

MsgBox x
Timer
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
Sub Timer()  Application.OnTime Now + TimeValue("00:00:01"), "Main" End Sub   Sub Main() Dim i As Long Dim x As String i = 1 For i = 1 to 100 x = Worksheets("Sheet1").Cells(i, 1).Value Next i MsgBox x Timer End Sub
</pre>
 
Upvote 0
I got it to work this way:

Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Timer2()
Dim i As Long
Dim x As String
i = 1
Do
    x = Worksheets("Sheet1").Cells(i, 1).Value
    MsgBox x
    Sleep (1000) ' delay 1 second
    i = i + 1
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,428
Members
448,896
Latest member
MadMarty

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