+ Reply to Thread
Results 1 to 5 of 5

Converting Text to Dates - TextToColumns

  1. #1
    Registered User
    Join Date
    05-27-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Converting Text to Dates - TextToColumns

    Hi all,

    I have a bunch of worksheets that have dates saved as 'text' and not as a 'date'. I wrote a macro to correct this on a per-cell basis using DateValue(), but I was hoping to be able to use TextToColumns to do all the work, as it seems much simpler and quicker to me.

    Unfortunately, I'm running into a problem with it working perfectly fine on most sheets but not all. I attached two small sample sheets - before I run my macro and after. On the next to last worksheet, the date format is not changed even though the macro correctly identifies it and attempts to change it (verified by stepping through the macro manually). Is there something I'm doing wrong here? I'm trying to get a final date format of day-month-year, but I found that I have to specify "mm-dd-yy" as the NumberFormat to get it to correctly show. Not sure why that is, either...

    Please Login or Register  to view this content.
    At the end, I'm not sure if there will be any issues with "Date" having a date number format or not so I figured I'd change it back to be safe.

    Thanks for any help!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Converting Text to Dates - TextToColumns

    Hi,

    instead of looping all cells and checking their numberformat for text it's faster to find the heading "Date" in a sheet and perform the operation for the entire range, additionally I noticed that the text dates 'before' have the format dd-mm-yy but textToColumns is expecting mm-dd-yy, so try:
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-27-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Converting Text to Dates - TextToColumns

    Hi,

    Thanks, that works great! I hadn't used Find() before, so that's good to know how it works. It's also good to know that you don't have to Activate each sheet to run, which I had to do before.

    If TextToColumns expects "mm-dd-yy", would it be best to convert the NumberFormat first? All of our dates are "dd-mm-yy", and we need to keep it as such in the end.

    I also have one question about the FieldInfo bit - why did you choose to use Array(0,4) instead of Array(1,4)? The built-in help files don't have anything about a 0 XlColumnDataType, and when I recorded a macro to see how TextToColumns works, it generated Array(1,4).

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Converting Text to Dates - TextToColumns

    Quote Originally Posted by FASTiger View Post
    Why did you choose to use Array(0,4) instead of Array(1,4)? The built-in help files don't have anything about a 0 XlColumnDataType, and when I recorded a macro to see how TextToColumns works, it generated Array(1,4).
    Weird, I recorded a macro too and it showed Array(0,4)

  5. #5
    Registered User
    Join Date
    05-27-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Converting Text to Dates - TextToColumns

    Quote Originally Posted by tehneXus View Post
    Weird, I recorded a macro too and it showed Array(0,4)
    That is weird...

    Ah well, thanks for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1