Excel VB - copying formatted dates programatically

G

Glenn

I have a date field with "yymmdd" format. I want to programatically convert
that to text that looks identical to the formatted date for use in
dimensioned variables/strings.
e.g. - date 6/10/2008 formatted looks like "080610". I want to use a/the
text string "080610" for various other uses. Can anyone help?
 
J

Jim Thomlinson

I am assuiming you have an actual date and not a string to be converted.

dim strDate as string
strdate = format(range("A1").value, "yymmdd")
 
G

Glenn

Many thanks - I found a longer way involving month, day, and year functions,
but this is clean. Yes, I have an actual date. thanks gain.....
 
J

Jim Thomlinson

If you format the date in the approproately in the spreadsheet the you could
just use

dim strDate as string
strdate = range("A1").text
 
G

Glenn

What I love about VB is there are often many ways to skin the cat. Thanks
again for your insight and options.
 

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