Excel Vba- Userform stopwatch

S

stevieh

Hi People,

I am currently trying to code s stopwatch function.

At present the function i have created has two command buttons, on
start and one stop which gives the date and time from clicking eac
button (one in a1 the other b1)

What i want it to do is not overwrite the information each time bu
just go to the next line, how do i do that?

Cheers

Steve

Code currently is

Private Sub CommandButton1_Click()
Range("A1").Value = Date
Range("A2").Value = Time
End Sub

Private Sub CommandButton2_Click()
Range("b1").Value = Date
Range("b2").Value = Time
End Su
 
C

Chip Pearson

Steve,

Try something like

Dim Rng As Range
Set Rng = Cells(Rows.Count,"A").End(xlUp)(2,1)
Rng(1,1).Value = Date
Rng(2,1).Value = Time


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
S

stevieh

hi,

how can i make it so that a1 is never older than b1. i.e

a1=1 b1=2 correct

a1=2 b1=1 incorrect

basically to stop someone clicking stop before star
 
S

stevieh

hi,

how can i make it so that a1 is never older than b1. i.e

a1=1 b1=2 correct

a1=2 b1=1 incorrect

basically to stop someone clicking stop before start

cheers

stev
 
D

Dave Peterson

Maybe you could stop them from clicking the buttons out of order.

I put 3 buttons on a userform--btnStart, btnStop, btnCancel.

Then I tried this:

Option Explicit
Private Sub btnCancel_Click()
Unload Me
End Sub
Private Sub btnStart_Click()
Call UpdateButtons
End Sub
Private Sub btnStop_Click()
Call UpdateButtons
End Sub
Private Sub UserForm_Initialize()
Me.btnStop.Enabled = False
End Sub
Private Sub UpdateButtons()

Dim rng As Range

With Worksheets("sheet1")
Set rng = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

rng.Value = Date
rng.Offset(0, 1).Value = Time
If Me.btnStart.Enabled Then
rng.Offset(0, 2).Value = "Start"
Else
rng.Offset(0, 2).Value = "Stop"
End If

Me.btnStart.Enabled = (Not Me.btnStart.Enabled)
Me.btnStop.Enabled = (Not Me.btnStop.Enabled)
Me.btnCancel.Enabled = (Not Me.btnCancel.Enabled)

End Sub
 
Top