Date Function

T

Taurus

I am working on VBA importing data from spreadsheet to the I/O object.
I couldn't import the date in the spreadsheet to I/O?
The format of the date in the spreadsheet is General format "19880413"
and I am not allow to change the format in the spreadsheet.
I would like to convert to "dd/mm/yyyy"
and I try to put in IO using Cdate() and it doesn't work.
Please advise.
 
B

Bernard Rey

Taurus said:
The format of the date in the spreadsheet is General format "19880413"
and I am not allow to change the format in the spreadsheet.
I would like to convert to "dd/mm/yyyy"
and I try to put in IO using Cdate() and it doesn't work.

The string "19880413" being no valid date format, it can't be considered as
such in a VBA macro. As you can't convert it in the sheet, you'll have to do
it in the macro.
One way could be:

Dim OrDate As String
OrDate = Range("A1").Value
MyDate = Left(OrDate, 4) & "/" & Mid(OrDate, 5, 2) & _
"/" & Right(OrDate, 2)
TrueDate = CDate(MyDate)
 
B

Bob Greenblatt

I am working on VBA importing data from spreadsheet to the I/O object.
I couldn't import the date in the spreadsheet to I/O?
The format of the date in the spreadsheet is General format "19880413"
and I am not allow to change the format in the spreadsheet.
I would like to convert to "dd/mm/yyyy"
and I try to put in IO using Cdate() and it doesn't work.
Please advise.
Dates of format yyyymmdd are interpreted as text, not a date. In VBA you
will have to parse the text string into separate fields and then convert to
a date. An easy way to do this manually is via the text-to-columns command
in the data menu. It will convert these strings to dates automatically.
 

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