Help with VB Code Please

Get_Involved

Active Member
Joined
Jan 26, 2007
Messages
383
I have this VB code in Module1

Code:
 Dim TimerActive As Boolean
Sub StartTimer()
    Start_Timer
End Sub
Private Sub Start_Timer()
    TimerActive = True
    Application.OnTime Now() + TimeValue("00:00:01"), "Timer"
End Sub
Private Sub Stop_Timer()
    TimerActive = False
End Sub
Private Sub Timer()
    If TimerActive Then
        ActiveSheet.Cells(6, 3).Value = Date + Time
        Application.OnTime Now() + TimeValue("00:00:01"), "Timer"
    End If
End Sub

And this code in ThisWorkbook

Code:
Private Sub Workbook_Open()
    Module1.StartTimer
End Sub

This code is working.
I have 8 sheets in this workbook, and the code puts the clock on all 8 sheets when opening
How can I restructure the code to only run on Sheet2?
I have tried everything, then it doesn’t work at all.
Any help would be appreciated.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi,

What happens if you try to replace 'ActiveSheet' with 'Sheets(2)' or 'Sheet2' or 'Sheets("name_of_sheet2<name_of_sheet2>")'?</name_of_sheet2>
 
Last edited:
Upvote 0
What happens I try to replace 'ActiveSheet' with 'Sheets(2)' or 'Sheet2' or 'Sheets("name_of_sheet2")'?
I get Debug with a yellow high lite all the way across, or a red high lite at the word Cells.
 
Last edited:
Upvote 0
.
Paste the following into a Routine Module :


Code:
Option Explicit


Dim TimerActive As Boolean
Sub StartTimer()
    Start_Timer
End Sub
Private Sub Start_Timer()
    TimerActive = True
    Application.OnTime Now() + TimeValue("00:00:01"), "Timer"
End Sub
Private Sub Stop_Timer()
    TimerActive = False
End Sub
Private Sub Timer()
    If TimerActive Then
        Sheet2.Cells(6, 3).Value = Date + Time
        Application.OnTime Now() + TimeValue("00:00:01"), "Timer"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

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