Share via

Text to columns (date conversion error) while using MACROs

Anonymous
2010-10-10T11:31:28+00:00

M trying to convert a date column (eg 31/12/2010 format) into Dec-2010 format.

I use the text to column function in excel 2007.

Whilst recording the macro, it converts everything perfectly, including the date requirement.

However, when I run the macro on a fresh set of text, it converts the text to columns, but some - not all - of the date fields swap the day and month numbers around (i.e. as in the US date display), whilst the remaining dates revert back to text.

An extra catch is that the sheet reads the cells in the european date configuration, so the day becomes the month and the month becomes the day.

e.g. 31/12/2010 - displayed as 12/2010  when working properly, becomes 31/2010

So, my question....

Why does the text to column conversion work when done manually but won't work as a macro?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2010-10-10T15:20:25+00:00

    Bonsour®

    "Fazi67" a écrit

    M trying to convert a date column (eg 31/12/2010 format) into Dec-2010 format.

    I use the text to column function in excel 2007.

    Whilst recording the macro, it converts everything perfectly, including the

    date requirement.

    However, when I run the macro on a fresh set of text, it converts the text to

    columns, but some - not all - of the date fields swap the day and month numbers

    around (i.e. as in the US date display), whilst the remaining dates revert back

    to text.

    An extra catch is that the sheet reads the cells in the european date

    configuration, so the day becomes the month and the month becomes the day.

    e.g. 31/12/2010 - displayed as 12/2010  when working properly, becomes

    31/2010<http://www.excelforum.com/images/smilies/confused.gif>

    So, my question....

    Why does the text to column conversion work when done manually but won't work

    as a macro?

    it's a little tricky ;o)))

    when recording "you" are using worksheet interface ...

    though" you" use local format for dates (Excel Options properties)

    but ...

    macro(VBA)  "always" use US langage i.e. US format for dates !!!

    so when recording the macro (step 3 in convert wizard)

    you have to precise  for the date fields  the format you read

    i.e.  DMY versus MDY

    HTH

    Was this answer helpful?

    0 comments No comments