+ Reply to Thread
Results 1 to 6 of 6

VBA to convert text dates to integer dates for entire column

  1. #1
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    VBA to convert text dates to integer dates for entire column

    Hello!

    I have a CSV file and in Col. C and F are dates (however some cells are blank).

    Sometimes when I open the file, some of these dates are formatted as text (left aligned) and not dates (right aligned). Changing the format of these cells to 'Date' doesn't fix the problem - the cells remain as they are. This means that my other code will not work.

    So, I have created a macro to loop through the data set and convert any of these text dates to integer dates;

    Please Login or Register  to view this content.
    However, this code takes a while to run.

    Is there a quicker way to do this - or does anyone know why I'm getting this problem when I open my CSV file?

    I have attached the file so you can see what I'm talking about.

    Any help would be much appreciated!

    Thank you!
    Attached Files Attached Files
    Last edited by benjhardie; 02-25-2019 at 04:52 PM.

  2. #2
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to convert text dates to integer dates for entire column

    Ignore this comment - I solved this part.

    I've also just noticed that this method switches the dates to US style (e.g. mm/dd/yy) and I need them in UK style (e.g. dd/mm/yy).

    Does anyone know how to do this?
    Last edited by benjhardie; 02-25-2019 at 04:55 PM.

  3. #3
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to convert text dates to integer dates for entire column

    I've actually discovered the real problem here. For some strange reason, sometimes when I open the CSV file, the days and months are swapped around (e.g 08/02/2019 is changed to 02/08/2019). However, this obviously isn't logically possible for all dates and so they are left as a text string (e.g 25/02/2019 can't be changed to 02/25/2019 as there is no 25th month - so this is left as text). I have no idea why this is happening.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA to convert text dates to integer dates for entire column

    How are you opening the CSV file?
    If posting code please use code tags, see here.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: VBA to convert text dates to integer dates for entire column

    benjhardie

    Don't open csv by just clicking the file icon.

    See
    https://support.office.com/en-us/art...b-339e391393ba

    You can specify data type column by column.

  6. #6
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to convert text dates to integer dates for entire column

    Thank you so much for the help! I have created some code to open the CSV using the Import Text Wizard and it is working nicely

+ 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. Convert Text Dates to Real Dates?
    By NewYears1978 in forum Excel General
    Replies: 11
    Last Post: 04-20-2017, 07:42 PM
  3. VBA to loop different length text dates to convert to Dates
    By earlyfreak in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-13-2016, 06:15 PM
  4. Count of Dates Contained in an Entire Column
    By gpzbc in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-03-2013, 02:54 PM
  5. Convert column of dates to actual dates
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-22-2013, 10:57 AM
  6. Convert Text Dates, Perform Calculation, Convert back to Text
    By Orada in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2012, 05:25 PM
  7. Replies: 4
    Last Post: 02-02-2012, 09:24 AM

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