Start/Stop Timer

nsguy_98

New Member
Joined
Sep 24, 2014
Messages
4
Hi Everyone!

first, I'm not good at creating VBAs from scratch. I usually get ideas from the forums then putting everything together to build a macro. I am trying to create a timer macro using Active X Control Button so that when I click "Start", the button will automatically switch to "Stop". at the same time, the start and stop time will be displayed in two different column like the example below.

121zdbm.png
[/IMG]

furthermore, I need the timers to show and align with the given intervals indicated.

here are the codes I have so far

Option Explicit

Private Sub StartTimer_Click()
If StartTimer.Caption = "Start" Then
StartTimer.Caption = "Stop"
-----'if its possible to incorporate the start timer in this line
Else
StartTimer.Caption = "Start"
-----'if its possible to incorporate the stop timer in this line
End If
End Sub


and here are some codes that I'm trying to put together with the active X.

Option Explicit

Public Sub StartTimer()
timer.Cells(StartRowOffset(timer.[StartTitles]), timer.[StartTitles].Column).Value = Format(Now(), "HH:MM:SS AM/PM")
End Sub


Public Sub EndTimer()
timer.Cells(StartRowOffset(timer.[EndTitles]), timer.[EndTitles].Column).Value = Format(Now(), "HH:MM:SS AM/PM")
End Sub

Public Sub ClearTimer()
timer.Range(timer.[StartTitles].Offset(1, 0), timer.[EndTitles].Offset(StartRowOffset(timer.[EndTitles]), 0)).Clear
End Sub


Private Function StartRowOffset(rStart As Range) As Long
Dim startPoint As Range
Dim currentRows As Long

On Error GoTo err_h

StartRowOffset = timer.[StartTitles].Row + extendRangeDownLast(rStart).Rows.Count

exit_proc:
Exit Function
err_h:
StartRowOffset = 10 '0
End Function

'Sub test()
' MsgBox StartRowOffset
'End Sub



note: credit to codematic for the format and codes above.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,215,479
Messages
6,125,041
Members
449,206
Latest member
Healthydogs

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