Start Stop Button!

atif_ar

New Member
Joined
May 31, 2014
Messages
31
Dears,

Help me in making one Button which I press enter the time in B10 and Press again it will enter in C10 with time difference in D10. And when I press again it will enter time in B11 and if I press again it will enter in C11 and time difference automatically in D11 and keep on going if I have a data in A10 or A11 and so on
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Lightly tested, but give this a try. Runs from a forms control command button on the sheet where you want the times entered. I haven't included anything additional to reset the counter.
Code:
Sub Button1_Click()
Static Ct
Dim NxRw As Long
If Range("A10") <> "" Then
    NxRw = 10
Else
    Exit Sub
End If
If IsEmpty(Range("B10")) Then
    Ct = Ct + 1
    [B10] = Now
ElseIf IsEmpty(Range("C10")) Then
    Ct = Ct + 1
    [C10] = Now
Else
    NxRw = Cells(Rows.Count, "C").End(xlUp).Row + 1
    If Cells(NxRw, "A").Value <> "" Then
        If Ct Mod 2 <> 0 Then
            Cells(NxRw, "C").Value = Now
            Ct = Ct + 1
        Else
            Cells(NxRw, "B") = Now
            Ct = Ct + 1
        End If
    Else
        Exit Sub
    End If
End If
If Cells(NxRw, "C").Value <> "" Then
    Cells(NxRw, "D").Value = Cells(NxRw, "C").Value - Cells(NxRw, "B").Value
End If
Range("B10:D" & NxRw).NumberFormat = "hh:mm:ss"
End Sub
 
Upvote 0
Thanks a lot dear the code is working gr8 but the start / stop button caption should change to start when it is pressed once and stop when pressed again when the time is calculated. Also if you can help to add time reset button and time total of the column D in Cell A1.

You are the best I want to learn how you coded this step by step. Please make me your student please please please
 
Upvote 0
Thanks a lot dear the code is working gr8 but the start / stop button caption should change to start when it is pressed once and stop when pressed again when the time is calculated. Also if you can help to add time reset button and time total of the column D in Cell A1.

You are the best I want to learn how you coded this step by step. Please make me your student please please please
You are welcome.

The modified module below should satisfy your additional requests.
Code:
Sub Button1_Click()
Static Ct
Dim NxRw As Long, Shp As Object
Application.ScreenUpdating = False
Set Shp = ActiveSheet.Shapes.Range(Array("Button 1"))
Shp.TextFrame.Characters.Text = "Start"
If Range("A10") <> "" Then
    NxRw = 10
Else
    Exit Sub
End If
If IsEmpty(Range("B10")) Then
    Ct = 0
    [B10] = Now
    Shp.TextFrame.Characters.Text = "Stop"
    Ct = Ct + 1
    
ElseIf IsEmpty(Range("C10")) Then
    Ct = Ct + 1
    [C10] = Now
    Shp.TextFrame.Characters.Text = "Start"
Else
    NxRw = Cells(Rows.Count, "C").End(xlUp).Row + 1
    If Cells(NxRw, "A").Value <> "" Then
        If Ct Mod 2 <> 0 Then
            Cells(NxRw, "C").Value = Now
            Ct = Ct + 1
            Shp.TextFrame.Characters.Text = "Start"
        Else
            Cells(NxRw, "B") = Now
            Ct = Ct + 1
            Shp.TextFrame.Characters.Text = "Stop"
        End If
    Else
        Exit Sub
    End If
End If
If Cells(NxRw, "C").Value <> "" Then
    Cells(NxRw, "D").Value = Cells(NxRw, "C").Value - Cells(NxRw, "B").Value
End If
With Range("B10:D" & NxRw)
    .NumberFormat = "hh:mm:ss"
    [A1] = Application.Sum(.Columns(3))
End With
Application.ScreenUpdating = True
End Sub

Sub Button2_Click()
'Resets the timestamp range and sum cell (A1)
Range("B10:D" & Cells(Rows.Count, "B").End(xlUp).Row).ClearContents
Range("A1").ClearContents
End Sub
 
Upvote 0
Dear love you for that.

The code really works. Now I am disturbing you again. I want that when the day overs automatically / any click of button all start/stop timings will be archived / saved on other workbook / sheet and this sheet will again be ready for new entries for the day for the start and stop timings.
Also their will be a check box if we enable it then at the click of start / stop button if user not inputs and entry within 5 mins the next start time will automatically appears with "break" remarks/comments in E column; and if user press the start/stop button msgbox will appear asking you want to add activity / consider this time as "break" then at the press of "Yes" he can manually stop the time but if press no the end time will be added with comments as Break.

Sorry I am disturbing but you're the best and thanks always for helping me
 
Upvote 0
You are welcome. Glad I could help you to this point. Your new requests can be handled with code that is independent of what I've given you and a lot more detail is needed to provide it. I suggest you start a new thread for it.
 
Upvote 0
You are welcome. Glad I could help you to this point. Your new requests can be handled with code that is independent of what I've given you and a lot more detail is needed to provide it. I suggest you start a new thread for it.

Thanks for your reply really really thanks. Just tell me dear how I can get further help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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