command button code

D

dummy

I have this formula in cell B9
=IF(B10="","",IF(B9="",NOW(),B9))
This puts the current time(remaining static) in B9 anytime something is
entered into B10.
What I would like to do is have one of the command buttons or check boxes in
B10 that would trigger the action.
Thanks for any help.
 
L

Luke M

Here is the coding for your button. Note that with the macro, you no longer
need the formula in cell B9:

'===============
Sub UpdateTime()
'Original formula for reference
'=IF(B10="","",IF(B9="",NOW(),B9))

If Range("B10") = "" Then
x = ""
ElseIf Range("B9") = "" Then
x = Now
Else: x = Range("B9")
End If
Range("B9") = x
End Sub
'===========
 
D

dummy

I'm getting a "compile error" "expected end sub". I copied and pasted your
code between :

Private Sub CommandButton1_Click()

End Sub

Is that correct?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top