+ Reply to Thread
Results 1 to 13 of 13

Force European Dates Format

  1. #1
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Force European Dates Format

    Dear all,

    Trust you’re all well.

    I have a dashboard with VBA forms that uploads csv files taken from our internal system to a specific dashboard.

    All info is being pasted on the right columns and so on, the only field giving me headaches is the one is being extracted with date and time even though, on the CSV file, the cells does not recognize the info as date. They came on the following format: “dd.mm.yyyy hh:mm:ss” as attached example in column “H”.

    The issue I have is with some colleagues based in the US. When I copy this info from CSV file into Excel as date, some of the dates comes in US format and some dates in European.
    E.g., if one of the dates are 08.01.2019, it will reverse to 1st of August 2019 instead of 8th of January 2019.

    As we do not need the hours; seconds and milliseconds, I have created a code to delete it and only paste the date.

    The code I use to copy from CSV file and paste to XLSM file is the following:
    Please Login or Register  to view this content.
    On first line of code, I have forced to format the column target as “text” to avoid excel mix the dates.

    My goal is to paste the dates and force the European format such as e.g. “1st March 2019”.

    Any ideas will be highly appreciated.

    Best regards,
    Filipe
    Attached Files Attached Files


    * If a reply solved or answered your query/question, you can add reputation to the person by clicking on the * Add Reputation
    * When question is resolved, please mark your thread as SOLVED


    Thanks and regards,
    Filipe Oliveira

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,855

    Re: Force European Dates Format

    Administrative Note:
    Welcome to the forum
    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums.
    Read this to understand why we (and other sites like us) consider this to be important.

    (note: this request is not optional No Help to be offered until the link is provided)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hi All,

    As per Admin request and as per the rules, I have also created this same thread on other Excel forum with the following link:

    https://www.mrexcel.com/forum/excel-...es-format.html

    Any assistance will be highly appreciated.

    Best regards,
    Filipe

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Force European Dates Format

    Hi.
    See if the attached works for your needs.
    torachan.
    Attached Files Attached Files

  5. #5
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Force European Dates Format

    Hi Pipoliveira,

    In your code you leave the identification of dates to the interpretation of excel in the For Each Cell In Range("F14:G1000") loop. This can cause problems if the date separator (in your export.csv it is point) is not recognized by the local settings then dates will often stay text. f.e. on my system dates are separeted with minus so 08-03-2019 for today.
    Another common problem is (as you have noticed) that if excel does recognize a date but the day is under between 1 and 12 then days can get swithed around if you only shorten the string to the date part. Left(cell,10) in your code

    The only way to be sure a date will be handled correct you will need to a proper conversion to datevalue in VBA yourselfyou can do that with the command dateserial. In your export file the date is always dd.mm.yyyy so that will be easy to put into a vba.

    I have created below code for you to test on your export.csv as I dont have the other file with range F you can use this code to test on export.csv and then later change the ranges in your own macro

    Please Login or Register  to view this content.
    dateparts is an small array that will split the first 10 characters of the date time text string into 3 parts based on pointseparator so rsulting in
    day=dateparts(0) month=dateparts(1) and year=dateparts(2)
    then the nextline replaces the current datestring with a datevalue. With cellformatting you can then control how to show the date.
    For use in international environments I always recommend to use a format with short monthname (Jan, Feb) instead of numeric months because that eliminates a lot of confusion of day and month. If a USA employee sees 08.Mar.2019 he might get annoyed that it is the wrong way around but he wont confuse the date for august 3rd

    so it is a bit of a mix of handling dates in VBA and choosing smart formatting for international use to eliminate confusion.
    Last edited by Roel Jongman; 03-08-2019 at 07:19 AM.

  6. #6
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Force European Dates Format

    Is this what you want at the press of a button.

    Capture.JPG
    Attached Files Attached Files
    Last edited by torachan; 03-08-2019 at 02:16 PM. Reason: spelling

  7. #7
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hi Torachan,

    Thanks for your replies.

    Your code seems to work ok but for that, you have merged (concatenated) all columns into one.

    I want to avoid that as I am looking for only copy the columns from the export file as export it properly as dates only in European format.

    For the US colleagues, they can after change it manually if they pleased.

    Thanks a million,
    Filipe

  8. #8
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hi Roel,

    Thanks a million for your reply and code.

    First, I have to take out the "Option Explicit" as the "dt" Dimension was not set.

    But even though, the code gave me an "Subscript out of range" on the following line:
    Please Login or Register  to view this content.
    Not sure how to debunk it.

    Thanks a million,
    Filipe
    Last edited by pipoliveira; 03-12-2019 at 09:57 AM.

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hey Roel,

    I've debunked a little your code and solved the out of range issue with error handler.

    The only thing I had to do is to format the cells into the date format desired ("d mmm yyyy").

    The final code works great as desired (little change from yours as I add this one to the Dashboard and not the sample):

    Please Login or Register  to view this content.
    Thanks a million for this piece of code and explanation.

    I am really appreciated

    Best regards,
    Filipe

  10. #10
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Force European Dates Format

    Is the 'EXPANDED' sheet the format you require ?
    torachan.
    Attached Files Attached Files

  11. #11
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hi Torachan,

    No, I did not wanted to merge all columns into one but only to force excel to accept the dates that were exported from the system (csv file) to european ones.

    The code from Roel converted the info copied from CSV file to the required date format.

    Best regards,
    Filipe

  12. #12
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Force European Dates Format

    Hi Roel,

    Trust you're well.

    I had to reopen this thread as I am having issues with my US colleagues that have on their system settings the US date format.

    Attached is the export file with the dates in US format.

    I have used your code and even I have tried to swap the DateSerial with no avail.

    Most of the values get recognized for US dates but, for example, cell H2 gives the date of 1st of December instead of 12th of January; Cell H27 gives 7th of February instead of 2nd of July.

    I will have to create 2 CommandButtons separately for European format and US format.

    My question is how to twist/change your code as to facilitate the US colleagues.

    Your assistance on this matter will be highly appreciated.

    Best regards,
    Filipe
    Attached Files Attached Files
    Last edited by pipoliveira; 03-21-2019 at 07:00 AM.

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

    Re: Force European Dates Format

    This is to swap day and month and remove time part and creates a new csv file.
    mm.dd.yyyy hh:mm(:ss)? to dd.mm.yyyy
    dd.mm.yyyy hh:mm(:ss)? to mm.dd.yyyy
    Please Login or Register  to view this content.

+ 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. Convert European dates to Excel-read dates
    By thepinkgeologist in forum Excel General
    Replies: 1
    Last Post: 09-21-2015, 10:33 AM
  2. Date time format US/European format bug?
    By rbulph in forum Excel General
    Replies: 4
    Last Post: 04-22-2013, 11:45 AM
  3. European Dates
    By jpnyc in forum Excel General
    Replies: 5
    Last Post: 08-10-2010, 11:36 AM
  4. Recognizing European Dates as Dates in Excel 2007
    By sdekker22 in forum Excel General
    Replies: 1
    Last Post: 10-25-2009, 05:07 PM
  5. CONVERT DATES FROM EUROPEAN FORMAT TO US FORMAT
    By les8 in forum Excel - New Users/Basics
    Replies: 13
    Last Post: 08-08-2006, 12:50 PM
  6. number of days between two dates in european format
    By manan in forum Excel General
    Replies: 3
    Last Post: 05-22-2006, 06:45 AM
  7. [SOLVED] Converting and sorting US dates into European format?
    By Eric G in forum Excel General
    Replies: 9
    Last Post: 12-05-2005, 11:40 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