+ Reply to Thread
Results 1 to 11 of 11

Date format changed after csv files imported to current excel workbook

  1. #1
    Registered User
    Join Date
    09-16-2018
    Location
    Melbourne
    MS-Off Ver
    1830
    Posts
    3

    Date format changed after csv files imported to current excel workbook

    Greetings all.

    I am a VBA newbie, currently studying and working on a personal project importing multiple .csv documents into my current workbook with their own different sheet, but I'm stuck at a stage where after csv files been imported to my current workbook, some dates are converted to mm/dd/yyyy, while their original formates are dd/mm/yyyy in csv. Also, some of the dates changed to 'general' type. As I am using dd/mm/yyyy format and aim to run date range filter, it always gave me incorrect outcome. I have now located the issue and have no idea how to fix them.

    After I run the followling macro, it imports my selected csv files and merge them with my current workbook, and the flexibility is my greatly prefered. It just the date format that confusing me. I have attached file1.csv which is one of my original file.

    Currnet VBA I am using as follows.
    Please Login or Register  to view this content.
    After I run the macro, the dates becomes totally different as what shown on csv file. see attachment 'Screen Capture' (list on the left side are incorrect data, left aligned are general type and right aligned are mm/dd/yyyy, and list on the right side are original data, which are what I wantted).

    Hope I have explained my confusion.

    Please kindly advise how can I fix the problem. Any help would be greatly appreciated. Thank you
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by FDibbins; 09-16-2018 at 11:31 PM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date format changed after csv files imported to current excel workbook

    Hi, welcome to the forum,
    I suggest you read the rules and see how to mark code as code in your text.
    I haven/t looked at your file but date format differences occur when the system settings differ. csv files are text files so make sure that you configure the date fields as date when reading them in Excel, You can do this the moment you read the csv file.
    If you start over and record a macro to import the csv file into an existing sheet, you will get the dialog in Excel and there you can set the format for the columns as you go, after you've done this look at the recorded code and you will see that the date columns have another type definition as the cells formatted as General or Integer or whatever.
    If I would import your csv file on my system with Dutch settings then the date will look different too and maybe even incorrect, 11/09/2018 which I would interprest at September 11 2018 could become November 9 2018, this would happen with all dates where the day is less than 13
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date format changed after csv files imported to current excel workbook

    I recorded a macro doing that

    Please Login or Register  to view this content.
    As you can see the first column is set as a date column, that is what the 4 stands for
    I get the same result you did so I honestly think it's a question on date settings.
    Last edited by Keebellah; 09-16-2018 at 09:20 AM. Reason: Typing errors

  4. #4
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Date format changed after csv files imported to current excel workbook

    Without error handling

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date format changed after csv files imported to current excel workbook

    @Vraag en antwoord: What about the date settings? There is no issue that requires error handling

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Date format changed after csv files imported to current excel workbook

    Jason, welcome to the forum

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html

    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Registered User
    Join Date
    09-16-2018
    Location
    Melbourne
    MS-Off Ver
    1830
    Posts
    3

    Re: Date format changed after csv files imported to current excel workbook

    Hi FDibbins,

    Apologize for the oversight, was too rushed to get things sorted as I have been stuck here for a while, and it's my first time posting on forum. Thank you for point out. I should have been more careful and read through the rules.

  8. #8
    Registered User
    Join Date
    09-16-2018
    Location
    Melbourne
    MS-Off Ver
    1830
    Posts
    3

    Re: Date format changed after csv files imported to current excel workbook

    Dear Vraag,

    Thank you so much for your help. I have tried your codes, it's very helpful and working perfectly fine, but it led me to another problem, all of my original file names are exceeded 31 characters, which excel does not allow. Could you please advise how to add related code to change each file name after the import? e.g importfile1, importfile 2 and so go.

    Also, could you please kindly write a brief note teaching me what does this code mean?
    Please Login or Register  to view this content.
    I am very keen to learn VBA. Much appreciated for your help.

    Thank you

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date format changed after csv files imported to current excel workbook

    Hi Jason,
    I like the Office Version you show in your profile 1830? New one for me
    Excel allows any length of filenames but I and thinking you mean Worksheet Tabs.
    That is true, the Sheet's tabs are limited to 31 characters.

    What I did is the following using a code like shown here

    Please Login or Register  to view this content.
    The only thins is that you will need to add a routine to check if the tab name already exists, since if you have more than one file where the first 31 characters is the same then you will need to add a counter.
    You could also do this with an On Error Trap

    Please Login or Register  to view this content.
    If you get stuck, just let us know

  10. #10
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Date format changed after csv files imported to current excel workbook

    @Keebellah,

    Please Login or Register  to view this content.
    Is a form of error handling that I meant
    And there are others that you have not mentioned, for example invalid characters in a sheet name.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date format changed after csv files imported to current excel workbook

    Yes, I have some code for that too and also for the worksheet names to number them if the left 31 are the same

+ 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] Multiple Text files imported in the current workbook.
    By dazziphoenix in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2014, 11:50 AM
  2. Replies: 6
    Last Post: 03-05-2010, 12:48 PM
  3. Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 AM
  5. Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  7. [SOLVED] Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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