Current time by clicking comm button in excel [Closed]

Report
Posts
1
Registration date
Monday July 12, 2010
Status
Member
Last seen
July 12, 2010
-
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
-
Hello,


how to get the current time by clicking command button for any active cell

3 replies

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
791
bring a "comman button" from the control toolbar and place it somewhere in the sheet.
right click the sheet tab and click view code. There you copy this code


Private Sub CommandButton1_Click()
ActiveCell = Now()
ActiveCell.NumberFormat = "hh:mm:ss"
End Sub
14
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

whr z cmmnd button in ctrl toolbar??i hv to wrk this thing in excel sheet & thr z no control toolbar thr.....
I wnt to display current time whn a cell of xcel sheet is clicked..
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
791
of course you can bring the button from the form toolbar. view-toolbars-form

alternatively do this
right click sheet tab and click view code.
there you copy this event code
AFTER SELECTING A CELL YOU HAVE TO RIGHT CLICK THE CELL


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) 
Cancel = True 
Target = Now() 
Target.NumberFormat = "hh:mm:ss" 
End Sub 

how to isolate it to certain cells.
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
791
if the relevant cells you want to have this result is only one paritcualr row(s) or column(s). if it is in a few particular cells in a row or column how many are there.

you can use a statement that if the selected cell is not the relevant cell then nothing should happen(that is exit sub)

so clarify this point.