LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default format cells with ### as number, then convert to string showing date.

What is the quickest way to make all the cells in defined range have the
number format (NumberFormat = "0") when
they show the hash sign due to an incompatible value with the date format?
These cells have values such as 18950315, which is an Interbase integer date
format.
After the format is changed to number these values will have to be converted
to a string showing the date.
All these values are pre Excel dates, but the problem is that they are
intermixed with normal Excel compatible dates
that are handled in a different way.

I have code that does the job, but it is slightly slow:

Sub ChangeHashesToDates(ByRef rng As Range, Optional ByVal strFormat As
String = "")

Dim c As Range

Application.StatusBar = _
" Converting pre Excel dates, please wait ..."

If strFormat = "" Then
For Each c In rng
If Len(c.Text) = 32 Then
c.NumberFormat = "0"
c.Text = Right(c.Value, 2) & "/" & _
Mid(c.Value, 5, 2) & "/" & _
Left(c.Value, 4)
End If
Next
Else
For Each c In rng
If Len(c.Text) = 32 Then
c.NumberFormat = "0"
c = Format(DateSerial(Left(c, 4), _
Mid(c, 5, 2), _
Right(c, 2)), _
strFormat)
End If
Next
End If

End Sub


Thanks for any advice.

 
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 Date string to date format Joe M. Excel Discussion (Misc queries) 7 May 6th 10 02:46 PM
Convert worksheet string name to date format in cell Sabosis Excel Worksheet Functions 2 September 4th 09 05:49 PM
convert number to date format Lesley Excel Discussion (Misc queries) 4 July 12th 06 09:17 PM
convert a string of into a date format Fred[_12_] Excel Programming 2 August 14th 03 11:56 PM


All times are GMT +1. The time now is 06:03 PM.

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

About Us

"It's about Microsoft Excel"