View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dagonini Dagonini is offline
external usenet poster
 
Posts: 18
Default need help with macro to convert number to date

I did a search on this site and found a macro to convert a number to a
date. So i tried to update it to match my situation. However, I get a
runtime error 13 type mismatch.

I have a column of birthdates that come across as 20050102 and I need
it to read 01/02/2005. This is the macro:

Sub makedate()

Dim NewDate As Date
Dim cell As Range, sStr As String

Set cell = Range("a:a")
NewDate = CDate(Mid(cell, 3, 2) & "/" & Left(cell, 2) & "/" &
Right(cell, 2))
sStr = Format(NewDate, "dd/mm/yyyy")

End Sub


This is the line that is giving the run time error: NewDate =
CDate(Mid(cell, 3, 2) & "/" & Left(cell, 2) & "/" & Right(cell, 2))

Does anyone have an idea of why?