Date format & Text to columns Macro

louie420

New Member
Joined
Apr 10, 2002
Messages
3
I run many queries. The date format of these queries as they come out of our database is always YYYY-MM-DD. They need to be formatted to MM/DD/YY. I would like to be able to change the format with one macro that can be used in any selected column. Please help me. Thanks.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
On 2002-09-17 17:44, louie420 wrote:
I run many queries. The date format of these queries as they come out of our database is always YYYY-MM-DD. They need to be formatted to MM/DD/YY. I would like to be able to change the format with one macro that can be used in any selected column. Please help me. Thanks.

Hi - welcome to the board!

When you say 'formatted' - do you mean that you have successfully inported data that is now being held as a date value (i.e. a number) & you want to change the way it is represented ('formatted'), or do you mean that you've imported some 'date' fields but they are now being held as text & you now need to change this to an appropriately formatted date value? What does =isnumber() on one of the cells with a 'date' in it return?

Paddy
 
Upvote 0
On 2002-09-17 18:28, PaddyD wrote:
On 2002-09-17 17:44, louie420 wrote:
I run many queries. The date format of these queries as they come out of our database is always YYYY-MM-DD. They need to be formatted to MM/DD/YY. I would like to be able to change the format with one macro that can be used in any selected column. Please help me. Thanks.

Hi - welcome to the board!

When you say 'formatted' - do you mean that you have successfully inported data that is now being held as a date value (i.e. a number) & you want to change the way it is represented ('formatted'), or do you mean that you've imported some 'date' fields but they are now being held as text & you now need to change this to an appropriately formatted date value? What does =isnumber() on one of the cells with a 'date' in it return?

Paddy

I suppose I've imported some 'date' fields but they are now being held as text & I now need to change this to an appropriately formatted date value? The =isnumber() returns "FALSE".
THANKS.
 
Upvote 0
2 options:

1) with a formula:

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

2) with a 'trick':
- highlight the column of text 'dates'
- go to Data | Text to columns
- click next twice
- select date & the YMD option from the drop down
- click finish

Recording these sets gives:<pre>

Sub dates()
'
' dates Macro
' Macro recorded 19/09/2002 by Paddy
'

'
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 5)
End Sub</pre>

which could be cleaned up a bit.

Paddy
This message was edited by PaddyD on 2002-09-18 14:20
 
Upvote 0
On 2002-09-18 14:13, PaddyD wrote:
2 options:

1) with a formula:

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

2) with a 'trick':
- highlight the column of text 'dates'
- go to Data | Text to columns
- click next twice
- select date & the YMD option from the drop down
- click finish

Recording these sets gives:<pre>

Sub dates()
'
' dates Macro
' Macro recorded 19/09/2002 by Paddy
'

'
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 5)
End Sub</pre>

which could be cleaned up a bit.

Paddy
This message was edited by PaddyD on 2002-09-18 14:20

Paddy,

I did use the record function you mentioned however, the Destination range is still literal. I need it to be variable dependent on what column the date format happens to be in.

Louie.
 
Upvote 0

Forum statistics

Threads
1,224,900
Messages
6,181,634
Members
453,059
Latest member
jkevin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top