Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Andy
 
Posts: n/a
Default Text to columns macro problem

I am opening a csv file in excel with many columns in the US date
format (mm-dd-yyyy). I need these all to be in the UK format
(dd-mm-yyyy). When I run text to columns on each column individually I
can choose the column data format MDY and it will reformat the dates
correctly. However when I recorded a macro to do this it doesn't work.

Does anyone have any idea why this works when you do it manually but
not via a macro.

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlDelimited, _
FieldInfo:=Array(1, 3)

and repeated for each column

Thanks,
Andy

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bas
 
Posts: n/a
Default Text to columns macro problem

If possible don't use the '-' symbol for delimiting and run:
Range("A:A").NumberFormat = "dd-mm-yyyy"

Hope this helps!

- Bas

Andy wrote:
I am opening a csv file in excel with many columns in the US date
format (mm-dd-yyyy). I need these all to be in the UK format
(dd-mm-yyyy). When I run text to columns on each column individually I
can choose the column data format MDY and it will reformat the dates
correctly. However when I recorded a macro to do this it doesn't work.

Does anyone have any idea why this works when you do it manually but
not via a macro.

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlDelimited, _
FieldInfo:=Array(1, 3)

and repeated for each column

Thanks,
Andy


  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Text to columns macro problem

If the values were brought in as dates, then I think it's too late.

Excel will convert anything it sees as a date to a date--when working with .csv
files.

And the ones that don't look like dates will be brought in as text.

I think the safest thing to do is to rename the .csv file to .txt

Then record that macro when you:
File|Open your *.txt file
use the text import wizard to specify the field type
(Use the mdy format)

Andy wrote:

I am opening a csv file in excel with many columns in the US date
format (mm-dd-yyyy). I need these all to be in the UK format
(dd-mm-yyyy). When I run text to columns on each column individually I
can choose the column data format MDY and it will reformat the dates
correctly. However when I recorded a macro to do this it doesn't work.

Does anyone have any idea why this works when you do it manually but
not via a macro.

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlDelimited, _
FieldInfo:=Array(1, 3)

and repeated for each column

Thanks,
Andy


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
Andy
 
Posts: n/a
Default Text to columns macro problem

Thanks Dave that seems to work. Still seems strange that it works when
I run it myself in Excel but not from a macro!

  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Text to columns macro problem

I meant to add that VBA is USA centric. It sees everything as good old USA'ian.

And if you run your macro against the .csv file (instead of .txt), you'll notice
that VBA ignores your settings when it imports each field.



Andy wrote:

Thanks Dave that seems to work. Still seems strange that it works when
I run it myself in Excel but not from a macro!


--

Dave Peterson
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
Macro problem in Excel pd Excel Discussion (Misc queries) 2 March 14th 06 05:49 AM
wrap text problem Tcs Excel Discussion (Misc queries) 1 March 5th 06 04:38 AM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
Urgent Help Required on Excel Macro Problem Sachin Shah Excel Discussion (Misc queries) 1 August 17th 05 06:26 AM
Text to columns will not shut off. Gerald Cornforth Excel Worksheet Functions 5 December 15th 04 01:39 AM


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