+ Reply to Thread
Results 1 to 7 of 7

Macro pastes dates in wrong format.

  1. #1
    Registered User
    Join Date
    12-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question Macro pastes dates in wrong format.

    I am pasting data from a csv file to an Excel spreadsheet. When pasted without the macro dates are correct, but when pasted via a macro, days and months are converted to months and days giving incorrect date values.

    I cannot find an appropriate command to change locale settings before pasting. Can you help please>

    ROD WEBSTER

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,163

    Re: Macro pastes dates in wrong format.

    Welcome to the Forum!

    Please show the code for the macro you're using. It would be even better to see both files you are working with.

    Note that we require 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 here


    To post a file:
    1. Under the text box where you type your reply click the Go Advanced button.
    2. In the next screen look above the reply box and click the "paper clip" icon. You will get a pop-up screen.
    3. In the pop-up, click Add then Select to select a file from your local drive
    4. Click the Upload button to upload the file
    5. Click Done to attach it.

    It will be displayed as an attachment underneath your post text. Alternatively as the last step you can click the Insert Inline button and a hyperlink to the file will be inserted directly into your post text in the spot where your cursor is set at the moment you click the button.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro pastes dates in wrong format.

    Bunker Roof slab.csvThanks for your reply Jeff. Instead of posting the code, I have attached the two files in question. These are START.xlsm and Bunker Roof slab.csv.

    The macro is run from the page named "Temp Input 1". The first date for input is the 9th of July 2013, but after copying in, it displays as the 7th of September. Of course, if you are in the USA, the above dates will probably come out differently. If you look at rows 39 and 40 on the "temp" page, the date should move on by one day, but it shows a jump of a month.

    ROD WEBSTER

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Macro pastes dates in wrong format.

    You haven't uploaded the workbook.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    12-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro pastes dates in wrong format.

    So sorry. Here it is. Too large for upload.

    ROD WEBSTERSTART.zip

  6. #6
    Registered User
    Join Date
    12-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro pastes dates in wrong format.

    Hi Trevor.
    Did you get the workbook ok?

    ROD

  7. #7
    Registered User
    Join Date
    12-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro pastes dates in wrong format.

    I have now discovered that pasting is not the problem. VBA changes some dates when opening a .csv file.
    1) In the file which was attached (Bunker Roof slab.csv), dates are corrupted down to row 183, but are ok for rows 184 and greater.
    2) When loading other similar .csv files that contain fewer columns, dates in more rows are corrupted, which suggests to me that the extent of the problem could be related to bandwidth.
    3) VBA does NOT change any data when it opens an Excel (.xlsx) file.
    This solves my particular problem, as all I need to do is save all .csv files as .xlsx. The pasting macro then generates the correct dates. The underlying problem with VBA and .csv files needs to be fixed though.
    ROD WEBSTER

+ 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. Replies: 1
    Last Post: 10-03-2012, 07:06 PM
  2. Replies: 2
    Last Post: 09-05-2012, 03:20 PM
  3. [SOLVED] Automating a macro that copies and pastes data and pastes 2 rows under the previous one.
    By thebank in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2012, 05:02 PM
  4. Odd paste problem, code pastes into wrong cell.
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2012, 11:03 AM
  5. Selects and pastes data from wrong column
    By tvac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2006, 02:09 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