convert 1006 to date (01/10/2006)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following requirement. In a cell i have dates that have been
imported
from another system. They are entered as follows,

1206 would be December 2006
605 would be June 2005
0101 would be January 2001
There are no date older than 0101.

I would like to convert the cells or copy to new cells in the following
format 01/12/2006. Because there is no specific day of the month in the
original data i am happy to have 01 as the default.

is this easily achievable?
 
try this. Notice the ONE dot before the items in the with statement.
Sub dodatefromtext()
For Each c In Selection
With c
.Value = DateSerial(Right(c, 2), Left(c, Len(c) - 2), 1)
.NumberFormat = "dd/mm/yyyy"
End With
Next c
End Sub
 
Just some added information:
Gary's response provides an actual date serial number which can be used in
further calculations. To have it appear as you specify, you would need to
format the cell with the formula with the appropriate date format you want to
see.
 

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

Back
Top