Time stamp format thru macro question

DroZ3

New Member
Joined
Mar 22, 2018
Messages
22
Office Version
  1. 365
Platform
  1. Windows
I created a machine performance audit sheet where every time a machine stops and restarts the user has to input the time of the stop and time of the restart of the machine in cells.
1628255895272.png



The formulas (more than in the image above) work well if all the time cells have the same format (hh:mm:ss).
For users who don't want to enter time manually I made this macro (CRTL-T) :

Sub InsertTime()
'
' InsertTime Macro
' Insert current time
'
' Keyboard Shortcut: Ctrl+t
'
ActiveCell.FormulaR1C1 = "=NOW()"
ActiveCell.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub


So far so good ... but the issue I have now is that people in our company have different language and time format on their laptop. Because of that the macro does not always inserts a time stamps with the hh:mm:ss time format, when that happens the formulas don't work properly.

QUESTIONS for the board :

1- what can I add to the macro to make sure the time entered in the cell is in format hh:mm:ss (military time like 2:00:00 or 14:00:00) ? Without changing the regional settings in Windows/Excel.
I assume I can do paste the NOW time according to a format set in the macro itself while not changing regional settings.

2- how can I restrain the use of the macro to only cells B28:C227 and D11:E12 ?

Thanks for the help.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
It shouldn't really matter what format the user enters the timestamp in as long as Excel recognises it as a date/time.

How are the formulas not working when the format isn't as expected?
 
Upvote 0
It shouldn't really matter what format the user enters the timestamp in as long as Excel recognises it as a date/time.

How are the formulas not working when the format isn't as expected?
At first I was thinking the same thing but I realized that if you do Time2 - Time1 while Time 1 and Time2 have dissimilar format then the formula throughs in an error.
 
Upvote 0
Solution : ActiveCell.FormulaR1C1 = Format(Now, "HH:mm:ss")
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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
Back
Top