Timer help

prakash_moturu

Board Regular
Joined
Nov 2, 2009
Messages
152
Code:
Private Sub CommandButton1_Click()
Sheet1.Range("A1").Value = "1"
Sheet1.Range("A2").Value = "2"
Sheet1.Range("A3").Value = "3"
Sheet1.Range("A4").Value = "4"
Sheet1.Range("A5").Value = "5"
Sheet1.Range("A6").Value = "6"
 
End Sub
Private Sub CommandButton2_Click()
For i = 1 To 6
For j = 1 To 7
Sheet1.Cells(i, j).ClearContents
Next
Next
 
End Sub

i need to call CommandButton1_Click() and CommandButton2_Click() alternatively
for every 5 second using timer .

please help me.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
hi

i tried like this but not working any problem with my code please check it

Code:
Public RunWhen As Double
Sub StartTimer()
   RunWhen = Now + TimeSerial(0, 0, 60)
   Application.OnTime EarliestTime:=RunWhen, Procedure:=twos_Click, Schedule:=True
   
End Sub

Private Sub ones_Click()
Sheet1.Range("A1").Value = "1"
Sheet1.Range("A2").Value = "2"
Sheet1.Range("A3").Value = "3"
Sheet1.Range("A4").Value = "4"
Sheet1.Range("A5").Value = "5"
Sheet1.Range("A6").Value = "6"
End Sub
Private Sub twos_Click()
For i = 1 To 6
For j = 1 To 7
Sheet1.Cells(i, j).ClearContents
Next
Next
StartTimer
End Sub
 
Upvote 0
hi,

Code:
Public RunWhen As Double
Sub StartTimer()
   RunWhen = Now + TimeSerial(0, 0, 10)
   Application.OnTime EarliestTime:=RunWhen, Procedure:="twos_Click", Schedule:=True
   
End Sub

Private Sub ones_Click()
Sheet1.Range("A1").Value = "1"
Sheet1.Range("A2").Value = "2"
Sheet1.Range("A3").Value = "3"
Sheet1.Range("A4").Value = "4"
Sheet1.Range("A5").Value = "5"
Sheet1.Range("A6").Value = "6"
End Sub
Private Sub twos_Click()
For i = 1 To 6
For j = 1 To 7
Sheet1.Cells(i, j).ClearContents
Next
Next
StartTimer
End Sub

it shows the fallowing error

c:\Documents and settings\admin\desktop\copy.xls'!twos_Click cannot be found
 
Upvote 0
Hi there,

I should have noticed that this is probably in Sheet1's worksheet module. If that is the case, you will need to qualify the procedure name. Try:

Rich (BB code):
Option Explicit
 
Dim RunWhen As Double
 
Sub StartTimer()
 
    RunWhen = Now + TimeSerial(0, 0, 10)
 
    Application.OnTime EarliestTime:=RunWhen, Procedure:="Sheet1.twos_Click", Schedule:=True
 
End Sub
 
Sub ones_Click()
    Sheet1.Range("A1").Value = "1"
    Sheet1.Range("A2").Value = "2"
    Sheet1.Range("A3").Value = "3"
    Sheet1.Range("A4").Value = "4"
    Sheet1.Range("A5").Value = "5"
    Sheet1.Range("A6").Value = "6"
End Sub
 
Private Sub twos_Click()
Dim i As Long, j As Long
 
    For i = 1 To 6
        For j = 1 To 7
            Sheet1.Cells(i, j).ClearContents
        Next
    Next
    StartTimer
End Sub
 
Sub KillTimer()
    Application.OnTime EarliestTime:=RunWhen, Procedure:="Sheet1.twos_Click", Schedule:=False
End Sub

Mark
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,562
Members
449,385
Latest member
KMGLarson

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