ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Coverting dates (https://www.excelbanter.com/excel-programming/312180-coverting-dates.html)

Tony

Coverting dates
 
Hi Group,

I have inherited a large spreadsheet full of payments
(about 5000 of them). Some dates are entered like so
01/01/04, 01/1/2004, 01.01.04, 01.1.2004.

Excel does not recognise the dates with full stops in
them. Is there a fast and efficient way for me to convert
and standardise all dates to dd/mm/yyyy?

Regards

Tony

tod

Coverting dates
 
You can use the substitute function in a formula or in
code.

In formula:

Assuming your dates are in column A, put this formula is
an empty column and fill down. Then copy the values over
those in column A. Then format the column for you
prefered date format.

=IF(LEN(SUBSTITUTE(A1,".",""))<LEN(A1),DATEVALUE
(SUBSTITUTE(A1,".","/")),A1)

This says that if the date has periods, replace them with
slashes.

In code, you do almost the same thing except that you
don't have to do the copy and pasting and formatting.

Dim Cell As Range
For Each Cell In ActiveSheet.Range("A2:A" &
ActiveSheet.Range("A65536").End(xlUp).Row)
If Len(Application.Substitute
(Cell.Value, ".", "")) < Len(Cell.Value) Then
Cell.Value = Application.Substitute
(Cell.Value, ".", "/")
Cell.NumberFormat = "dd/mm/yyyy"
End If
Next Cell

tod


-----Original Message-----
Hi Group,

I have inherited a large spreadsheet full of payments
(about 5000 of them). Some dates are entered like so
01/01/04, 01/1/2004, 01.01.04, 01.1.2004.

Excel does not recognise the dates with full stops in
them. Is there a fast and efficient way for me to

convert
and standardise all dates to dd/mm/yyyy?

Regards

Tony
.


Niek Otten

Coverting dates
 
Hi Tony,

=REPLACE(REPLACE(A1,3,1,"-"),6,1,"-")*1

Then format as date.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"Tony" wrote in message
...
Hi Group,

I have inherited a large spreadsheet full of payments
(about 5000 of them). Some dates are entered like so
01/01/04, 01/1/2004, 01.01.04, 01.1.2004.

Excel does not recognise the dates with full stops in
them. Is there a fast and efficient way for me to convert
and standardise all dates to dd/mm/yyyy?

Regards

Tony




Niek Otten

Coverting dates
 
In addition to my previous reply: The "-" symbol may be "/" in your case.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"Tony" wrote in message
...
Hi Group,

I have inherited a large spreadsheet full of payments
(about 5000 of them). Some dates are entered like so
01/01/04, 01/1/2004, 01.01.04, 01.1.2004.

Excel does not recognise the dates with full stops in
them. Is there a fast and efficient way for me to convert
and standardise all dates to dd/mm/yyyy?

Regards

Tony




Tony

Coverting dates
 
Tod,
Thank you for the response. Apologies for not replying
sooner but have just returned from a weekend break.
I liked the VB solution.
It successfully converted the periods to dd/mm/yy but now
I cannot format them to dd/mm/yyyy. I have checked the
affected cells (about 470) under general formatting and
they do not display the Excel date function i.e. 35321.
Is it possible to convert these cells to dates?

Regards

TOny

-----Original Message-----
You can use the substitute function in a formula or in
code.

In formula:

Assuming your dates are in column A, put this formula is
an empty column and fill down. Then copy the values over
those in column A. Then format the column for you
prefered date format.

=IF(LEN(SUBSTITUTE(A1,".",""))<LEN(A1),DATEVALU E
(SUBSTITUTE(A1,".","/")),A1)

This says that if the date has periods, replace them with
slashes.

In code, you do almost the same thing except that you
don't have to do the copy and pasting and formatting.

Dim Cell As Range
For Each Cell In ActiveSheet.Range("A2:A" &
ActiveSheet.Range("A65536").End(xlUp).Row)
If Len(Application.Substitute
(Cell.Value, ".", "")) < Len(Cell.Value) Then
Cell.Value = Application.Substitute
(Cell.Value, ".", "/")
Cell.NumberFormat = "dd/mm/yyyy"
End If
Next Cell

tod


-----Original Message-----
Hi Group,

I have inherited a large spreadsheet full of payments
(about 5000 of them). Some dates are entered like so
01/01/04, 01/1/2004, 01.01.04, 01.1.2004.

Excel does not recognise the dates with full stops in
them. Is there a fast and efficient way for me to

convert
and standardise all dates to dd/mm/yyyy?

Regards

Tony
.

.



All times are GMT +1. The time now is 11:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com