Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default need help with macro to convert number to date

Problem is that cell is the entire column A! and you can't take the Mid of
it!
set Cell = Range("A1") could work.
But you don't need a macro. there's a builtin feature to do what you want
Select the date(s)
Data/Text-to-Columns
click next twice to get to step 3
Click that it's a Date, and set the format to mdy, then click finish.

Bob Umlas
Excel MVP

"Dagonini" wrote in message
ups.com...
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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default need help with macro to convert number to date

I need to do this automatically. ok. i can mess with it some more.
I've been trying the text to date wizard and it isn't working for me.
it is just giving me the year. Aarg


Bob Umlas wrote:
Problem is that cell is the entire column A! and you can't take the Mid of
it!
set Cell = Range("A1") could work.
But you don't need a macro. there's a builtin feature to do what you want
Select the date(s)
Data/Text-to-Columns
click next twice to get to step 3
Click that it's a Date, and set the format to mdy, then click finish.

Bob Umlas
Excel MVP

"Dagonini" wrote in message
ups.com...
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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert number to date value saz2369 Excel Discussion (Misc queries) 8 October 13th 09 03:10 PM
Convert number to date Teri Excel Discussion (Misc queries) 7 May 18th 07 06:29 PM
Convert Date to number BigPig Excel Programming 2 May 12th 06 09:50 PM
Convert a number formatted as text to a number in a macro MACRE0[_5_] Excel Programming 2 October 22nd 05 02:51 AM
How do I convert Date serial number to date rdunne Excel Worksheet Functions 1 April 12th 05 03:04 PM


All times are GMT +1. The time now is 01:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"