Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default numbers to dates

I have a column of numbers that I need to convert to dates, such as:

7252003
11152001
3312002

Some have length of 7, and some are 8. I can do this manually by
adding "0" to the 7 length numbers, then Data, Text to Columns/Date.
Is there a way to do this (faster) in a macro?

Thanks,
Marc
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default numbers to dates

Dim rng as Range, cell as Range
set rng = Range(Cells(1,ActiveCell.Column), _
Cells(rows.count,ActiveCell.Column).End(xlup))
for each cell in rng
if len(cell.Text) = 7 then
Cell.Value = "'0" & Format(cell.value,"0000000")
End if
Next

--
Regards,
Tom Ogilvy

"Marc" wrote in message
om...
I have a column of numbers that I need to convert to dates, such as:

7252003
11152001
3312002

Some have length of 7, and some are 8. I can do this manually by
adding "0" to the 7 length numbers, then Data, Text to Columns/Date.
Is there a way to do this (faster) in a macro?

Thanks,
Marc



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default numbers to dates

thanks, Tom- the only problem with this method is speed-
it took me 64 seconds to process 10,000 records; and what
if I had to do 50,000? Does anyone know of a faster
method, possibly using arrays?

Thanks,
Marc



-----Original Message-----
Dim rng as Range, cell as Range
set rng = Range(Cells(1,ActiveCell.Column), _
Cells(rows.count,ActiveCell.Column).End(xlup))
for each cell in rng
if len(cell.Text) = 7 then
Cell.Value = "'0" & Format(cell.value,"0000000")
End if
Next

--
Regards,
Tom Ogilvy

"Marc" wrote in message
. com...
I have a column of numbers that I need to convert to

dates, such as:

7252003
11152001
3312002

Some have length of 7, and some are 8. I can do this

manually by
adding "0" to the 7 length numbers, then Data, Text to

Columns/Date.
Is there a way to do this (faster) in a macro?

Thanks,
Marc



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default numbers to dates

Try this:

Option Explicit

Sub ProcDAtes()
Dim rng As Range, cell As Range, i As Long
Dim lngCalc As Long, varr As Variant
Dim sngStart As Single, lngcnt As Long
sngStart = Timer

lngCalc = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set rng = Range(Cells(1, ActiveCell.Column), _
Cells(Rows.Count, ActiveCell.Column).End(xlUp))
varr = rng
For i = 1 To UBound(varr)
If Len(varr(i, 1)) = 7 Then
lngcnt = lngcnt + 1
varr(i, 1) = "'0" & Format(varr(i, 1), "0000000")
End If
Next
rng = varr
Application.Calculation = lngCalc
Application.ScreenUpdating = True
Debug.Print Timer - sngStart, "rows: " & rng.Rows.Count & " Processed: " &
lngcnt
End Sub

Did 55,000 cells in 1.5 seconds on my machine.

--
Regards,
Tom Ogilvy

"Marc" wrote in message
...
thanks, Tom- the only problem with this method is speed-
it took me 64 seconds to process 10,000 records; and what
if I had to do 50,000? Does anyone know of a faster
method, possibly using arrays?

Thanks,
Marc



-----Original Message-----
Dim rng as Range, cell as Range
set rng = Range(Cells(1,ActiveCell.Column), _
Cells(rows.count,ActiveCell.Column).End(xlup))
for each cell in rng
if len(cell.Text) = 7 then
Cell.Value = "'0" & Format(cell.value,"0000000")
End if
Next

--
Regards,
Tom Ogilvy

"Marc" wrote in message
. com...
I have a column of numbers that I need to convert to

dates, such as:

7252003
11152001
3312002

Some have length of 7, and some are 8. I can do this

manually by
adding "0" to the 7 length numbers, then Data, Text to

Columns/Date.
Is there a way to do this (faster) in a macro?

Thanks,
Marc



.



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
Stop dates from showing as numbers - when formated as dates JR Excel Discussion (Misc queries) 1 October 29th 08 04:38 PM
dates and numbers be_mcwayne Excel Discussion (Misc queries) 3 February 22nd 07 01:15 PM
why does dividing numbers give me dates and not numbers? dylan Excel Discussion (Misc queries) 1 June 21st 06 11:40 PM
Numbers To Dates bodhisatvaofboogie Excel Discussion (Misc queries) 13 May 22nd 06 05:31 PM
Dates to numbers John Excel Worksheet Functions 0 February 8th 05 11:45 AM


All times are GMT +1. The time now is 10:07 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"