How to convert mm/dd/yyyy date format to yyyymmdd

J

Jeff

I have a cell with a custom date format of m/d/yyyy h:mm,
I need to convert the date to yyyymmdd text. Does anyone
have a VB macro code snippet to do something like this?
I've tried text to columns but can't get it to work...any
help is appreciated.

Thanks.
 
R

Richard Adrian

Hi Jeff,

I can help with part of this - don't know if it will give u the end solution
you want, though...

I can help u get from m/d/yyyy to yyyymmdd.

You say you already have a cell with "m/d/yyyy h:mm". Select that cell;
press Ctrl+1 to access the Format dialogue box for that cell. Select the
tab number. in the category box, select "custom". Then, in the "type" box,
type "yyyymmdd" - just that. that will automatically change your m/d/yyyy
to yyyymmdd. You can also copy this format to any other cell in that
workbook to get from m/d/yyyy to yyyymmdd.

I don't understand what you mean when you write that you want to get from
the "h:mm" part to "text". What text exactly? It is possible to have Excel
just lose the h:mm in the cell so that you go from m/d/yyyy h:mm to plain
old yyyymmdd - but what's this text u want to add?

Hope this is of some help,

Richard.
 
K

Kim Mitchell

Using VBA, the command you want is:
Range("C2")=Format(Range("B2"),"yyyymmdd").

Kim
 
I

Ian

Can you not just format the cell using Custom format
(Format>Cells>Custom Format) and type yyyymmdd ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top