#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Format Date

I have a column with the data type as general - This column should be a date

Sample data
20051231
20051230
20051229
20051228
20051227

I would like to write a rutine that would convert the date to

12/31/2005
12/30/2005
12/29/2005
12/28/2005
12/27/2005

Please I need help!!!!!!

thank you in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Format Date

try:

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
--
Gary''s Student


"Chris" wrote:
I have a column with the data type as general - This column should be a date

Sample data
20051231
20051230
20051229
20051228
20051227

I would like to write a rutine that would convert the date to

12/31/2005
12/30/2005
12/29/2005
12/28/2005
12/27/2005

Please I need help!!!!!!

thank you in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Format Date

Hi,
From the date format I am assuming you US-based. Try:

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

Create new column following your date column, copy in the formula with
apprpriate column change and copy down.

Edit==Copy the column then Edit==Paste Special ==Values on same column.
If OK, delete source column.

As I am UK-based I used the following to get your format:

=TEXT(DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)),"MM/DD/YYYY")


TEST first!


HTH
"Chris" wrote:

I have a column with the data type as general - This column should be a date

Sample data
20051231
20051230
20051229
20051228
20051227

I would like to write a rutine that would convert the date to

12/31/2005
12/30/2005
12/29/2005
12/28/2005
12/27/2005

Please I need help!!!!!!

thank you in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Format Date

Give this a try... It will only overwrite values, not formulas.

Public Function ConvertToDate(ByVal DateNumber As Long) As Date
ConvertToDate = DateSerial(CInt(Left(DateNumber, 4)), _
CInt(Mid(DateNumber, 5, 2)), CInt(Right(DateNumber, 2)))
End Function

Sub test()
Dim rngToSearch As Range
Dim rng As Range

Set rngToSearch = Sheets("Sheet1").Columns("A").SpecialCells(xlConst ants)
For Each rng In rngToSearch
rng.Value = ConvertToDate(rng.Value)
Next rng

End Sub
--
HTH...

Jim Thomlinson


"Chris" wrote:

I have a column with the data type as general - This column should be a date

Sample data
20051231
20051230
20051229
20051228
20051227

I would like to write a rutine that would convert the date to

12/31/2005
12/30/2005
12/29/2005
12/28/2005
12/27/2005

Please I need help!!!!!!

thank you in advance

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
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
How do I convert dd/mm/yy date format to yyddd Julian date format itzy bitzy[_2_] Excel Worksheet Functions 8 December 11th 09 03:20 AM
change date format dd/mm/yyyy to Julian date format? itzy bitzy Excel Worksheet Functions 1 December 8th 09 07:42 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


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