ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time Stamp (https://www.excelbanter.com/excel-programming/372860-time-stamp.html)

John Pierce

Time Stamp
 
Hello,
I have created a time stamp macro. A very simple one liner.

609140048 ActiveCell.Value = Format(Now(), "yymmddhhmm")
060914_0049 ActiveCell.Value = Format(Now(), "yymmdd_hhmm")
609140050 ActiveCell.Value = CStr(Format(Now(),
"yymmddhhmm"))

These are three different lines I have tried. I want it to be flush
left (text) and to have
the leading zero and as in the middle one but I don't want the
underscore or gap as
in the other ones. How can I get the best of both worlds?


RB Smissaert

Time Stamp
 
Sub test()

With ActiveCell
.NumberFormat = "@"
.Value = Format(Now(), "yymmddhhmm")
End With

End Sub

RBS


"John Pierce" wrote in message
oups.com...
Hello,
I have created a time stamp macro. A very simple one liner.

609140048 ActiveCell.Value = Format(Now(), "yymmddhhmm")
060914_0049 ActiveCell.Value = Format(Now(), "yymmdd_hhmm")
609140050 ActiveCell.Value = CStr(Format(Now(),
"yymmddhhmm"))

These are three different lines I have tried. I want it to be flush
left (text) and to have
the leading zero and as in the middle one but I don't want the
underscore or gap as
in the other ones. How can I get the best of both worlds?



John Pierce

Time Stamp
 
Thanks RB, that looks good, except for one itty-bitty problem.
In Excel 2003 it causes one of those usually-very-helpful
but sometimes-annoying error flags - in this case telling
me what I already know - that "The number in this cell is
formatted as text or is preceded by an apostrophe." Is
there anyway to programmatically prevent this, some
built-in error-checking. I tried recording the steps
involved in opening the message and selecting
"Ignore error" but nothing was recorded.


RB Smissaert

Time Stamp
 
Try:

Sub test()

Application.DisplayAlerts = False

With ActiveCell
.NumberFormat = "@"
.Value = Format(Now(), "yymmddhhmm")
End With

Application.DisplayAlerts = True

End Sub


RBS

"John Pierce" wrote in message
oups.com...
Thanks RB, that looks good, except for one itty-bitty problem.
In Excel 2003 it causes one of those usually-very-helpful
but sometimes-annoying error flags - in this case telling
me what I already know - that "The number in this cell is
formatted as text or is preceded by an apostrophe." Is
there anyway to programmatically prevent this, some
built-in error-checking. I tried recording the steps
involved in opening the message and selecting
"Ignore error" but nothing was recorded.



John Pierce

Time Stamp
 
Nice try but that didn't get it. Perhaps because the error
isn't caused by VBA but is on the spread sheet.



All times are GMT +1. The time now is 02:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com