+ Reply to Thread
Results 1 to 9 of 9

Change dates stored as text in table

  1. #1
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Change dates stored as text in table

    Hi,

    In the attached I have a table with some dates. Some of the dates are stored as text.

    I have recorded a macro (Macro1) that selects the table contents and then uses text to columns to convert the text dates to real dates. The recording works fine.

    If I put new dates in the table, once again some are text and try to run the same recorded macro, it doesn't change the dates as expected.

    Any ideas?
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kersplash; 05-30-2018 at 09:33 PM. Reason: added code

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change dates stored as text in table

    change this part specifically
    FieldInfo :=Array(1, 1) to FieldInfo :=Array(1, 4)


    https://msdn.microsoft.com/en-us/vba...meration-excel

    link explains more but its down to this basically
    Name Value Description
    xlDMYFormat 4 DMY date format.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Change dates stored as text in table

    Quote Originally Posted by humdingaling View Post
    change this part specifically
    FieldInfo :=Array(1, 1) to FieldInfo :=Array(1, 4)


    https://msdn.microsoft.com/en-us/vba...meration-excel

    link explains more but its down to this basically
    Name Value Description
    xlDMYFormat 4 DMY date format.
    I changed the code and it now changes the table, but it swaps the day and month for some of the dates???
    Capture.JPG

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change dates stored as text in table

    also selection not really required

    Please Login or Register  to view this content.

  5. #5
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Change dates stored as text in table

    Quote Originally Posted by humdingaling View Post
    also selection not really required

    Please Login or Register  to view this content.
    Thanks for the mod.

    But still have the same issue as Post #3
    Last edited by kersplash; 05-30-2018 at 09:50 PM.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change dates stored as text in table

    ok you made me go down a rabbit hole!!
    anyways this seems to do what you want

    Please Login or Register  to view this content.
    because adding zero to text = type mismatch

    it loops thru table to see if you get a type mismatch on any of the cells

    if it does...only apply text to column that that cell ONLY...i'm not sure if this kills performance but in the small scale nothing to write home about
    Last edited by humdingaling; 05-30-2018 at 10:56 PM. Reason: code cleanup...got rid of trim as it caused other issues

  7. #7
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Change dates stored as text in table

    Quote Originally Posted by humdingaling View Post
    ok you made me go down a rabbit hole!!
    Hahaha thanks for that. It drives me mad that when you record something it doesn't necessarily do the same thing as the recording.

    This works perfectly and I'm only running on small tables of data so performance shouldn't be a problem.

    Cheers

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change dates stored as text in table

    Cheers thanks for the rep

    yes i did notice the manual text to column seems to work which confused me too
    i think the problem is that VBA is US centric so once you get into date format.....all sorts of things you need to cater for

    the end solution was surprisingly easier than the research i encountered

  9. #9
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Change dates stored as text in table

    Quote Originally Posted by humdingaling View Post
    the end solution was surprisingly easier than the research i encountered
    Always the way.

    I've now added this to my multiple sheets and tables with the same issue and works like a charm on my real data size.

    Perfect!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Dates stored as Text and Values - convert entire column to date?
    By happydays886 in forum Excel General
    Replies: 12
    Last Post: 01-05-2018, 12:13 PM
  2. [SOLVED] fixing dates stored as text for pivot tables
    By td3201 in forum Excel General
    Replies: 2
    Last Post: 05-22-2017, 10:18 AM
  3. [SOLVED] VBA to change pivot table dates
    By excel291 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-11-2017, 06:21 PM
  4. Array changes dates stored as dates into text.
    By KNevland in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2014, 08:56 AM
  5. [SOLVED] Marco to convert numbers stored as text to numbers and dates stored as text to numbers
    By a2424 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2014, 10:19 AM
  6. Replies: 8
    Last Post: 01-16-2011, 07:27 PM
  7. Converting numbers stored as dates to text in Excel
    By David from Furdale in forum Excel General
    Replies: 1
    Last Post: 07-17-2006, 01:40 PM

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