Encoding Dates

D

daniel chen

I have dates in column A, and I would like to encode them in column B as
the following;
e.g.
For 12/6/2003 in columnA ColumnB should have 120603 in the same row.
For 8/5/2004 in columnA ColumnB should have 080504 in the same row.
For 8/17/2004 in columnA ColumnB should have 081704 in the same row.
Will someone help me with a formula, as well as VBA code, please.

I tried this one, and got erroneous ans.
Cells(1, 2) = Format(Cells(1, 1), "mmddyy")
 
J

JE McGimpsey

one way by formula:

=TEXT(A1,"mmddyy")

one way using VBA:

With Cells(1, 2)
.Value = Cells(1, 1).Value
.NumberFormat = "mmddyy"
End With

Note that when VBA enters a value in XL, XL's parser treats it like a
manual entry, so the format you enter it doesn't change how it's
displayed.
 
Top