command button code

  • Thread starter Thread starter dummy
  • Start date Start date
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.
 
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
'===========
 
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?
 
Back
Top