Can Excel automatically input times less than one second?

Paul B

Well-known Member
Joined
Feb 15, 2002
Messages
575
I know you can calculate times to 100th of a second by inputting them as hh:mm:ss.00. what I want to do is when I select a cell it will put the time in as h:mm:ss.00, the code below works for putting the time in, but I can’t get it to put the time in 100th of a second. If I put hh:mm:ss.00 as the format it returns the hours minutes and seconds but always gives me 00 for the 100th second part. Can this be done? I am using excel ’97 Thanks

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'puts time in columns B and C when you select them
With ActiveCell
Select Case .Column
Case 2, 3
If Not (.HasFormula Or .Text <> "") Then
ActiveCell = Now()
ActiveCell.NumberFormat = "hh:mm:ss"
End If
End Select
End With
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Strange isn't it. This seems to work:

Code:
Sub Test()
    ActiveCell.Formula = "=NOW()"
    ActiveCell.Value = ActiveCell.Value
    Selection.NumberFormat = "hh:mm:ss.00"
End Sub
 

Paul B

Well-known Member
Joined
Feb 15, 2002
Messages
575
Andrew, This is strange, if I run the sub once I get .00, if it is run again in the same cell it will display the 100th times, so I moved the Selection.NumberFormat = "hh:mm:ss.00" to the first line and it works! Thanks
 

Forum statistics

Threads
1,181,106
Messages
5,928,099
Members
436,588
Latest member
mummabare

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
Top