Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Nortos
 
Posts: n/a
Default Macro to convert text to date

I've been trying to record a Macro so that I can change text in columns to a
date format, I've used Text to columns to do this which works well outside a
Macro, but I have 20 columns to do on a weekly basis so would like to
automate it in a macro.

The imported file is in the following format "04/04/2005 10:17:51"
dd/mm/yyyy hh:mm:ss

I recorded a Marco, but it does not work in cells with a date 13+ for
example 13/04/2005 10:17:51 remains in text format?

Can any one let me know what I'm doing wrong or suggest VB code to solve this.

My knowledge of VB is poor, so go easy on me!
  #2   Report Post  
Alok
 
Posts: n/a
Default

You seem to be using US regional settings but the date text is in UK format.
Hence excel cannot convert it automatically into a date. The solution is to
switch your regional settings to English(United Kingdom) then do the Text to
columns changes and after completing the macro, save and close the workbook
and switch back to whatever your original regional setting was. Then open
your workbook and all dates should be OK.

Alok Joshi

"Nortos" wrote:

I've been trying to record a Macro so that I can change text in columns to a
date format, I've used Text to columns to do this which works well outside a
Macro, but I have 20 columns to do on a weekly basis so would like to
automate it in a macro.

The imported file is in the following format "04/04/2005 10:17:51"
dd/mm/yyyy hh:mm:ss

I recorded a Marco, but it does not work in cells with a date 13+ for
example 13/04/2005 10:17:51 remains in text format?

Can any one let me know what I'm doing wrong or suggest VB code to solve this.

My knowledge of VB is poor, so go easy on me!

  #3   Report Post  
Nortos
 
Posts: n/a
Default

My regional settings are UK, so it's not that and the text to columns works a
line at a time great, but when you record a macro that does it for a column
then another and so on it does not work corectly, see VB code example below:

Range("F14").Select
Application.Run "'Stage Report Test.xls'!ReturnToStartCells"
Sheets("Data import").Select
Columns("W:W").Select
Selection.TextToColumns Destination:=Range("W1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
Columns("X:X").Select
Selection.TextToColumns Destination:=Range("X1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
Columns("Y:Y").Select
Selection.TextToColumns Destination:=Range("Y1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
Columns("Z:Z").Select
Selection.TextToColumns Destination:=Range("Z1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
Range("A2").Select
Sheets("Macro").Select
Range("F14").Select
End Sub

Any ideas?

"Alok" wrote:

You seem to be using US regional settings but the date text is in UK format.
Hence excel cannot convert it automatically into a date. The solution is to
switch your regional settings to English(United Kingdom) then do the Text to
columns changes and after completing the macro, save and close the workbook
and switch back to whatever your original regional setting was. Then open
your workbook and all dates should be OK.

Alok Joshi

"Nortos" wrote:

I've been trying to record a Macro so that I can change text in columns to a
date format, I've used Text to columns to do this which works well outside a
Macro, but I have 20 columns to do on a weekly basis so would like to
automate it in a macro.

The imported file is in the following format "04/04/2005 10:17:51"
dd/mm/yyyy hh:mm:ss

I recorded a Marco, but it does not work in cells with a date 13+ for
example 13/04/2005 10:17:51 remains in text format?

Can any one let me know what I'm doing wrong or suggest VB code to solve this.

My knowledge of VB is poor, so go easy on me!

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
How to convert string to a date galsaba Excel Worksheet Functions 3 March 4th 05 05:20 PM
How do I convert a number formated as a date to text in Excel? BrotherNov Excel Discussion (Misc queries) 5 March 2nd 05 03:51 PM
Formula with text and reference to a date cell [email protected] Excel Discussion (Misc queries) 1 January 11th 05 08:15 AM
copying text into a macro pagelocator Excel Worksheet Functions 1 November 24th 04 08:52 AM
How to convert Numbers to text Calif_guy Excel Worksheet Functions 1 November 12th 04 05:12 AM


All times are GMT +1. The time now is 09:46 AM.

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"