+ Reply to Thread
Results 1 to 36 of 36

Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Hi

    I am having lots of trouble with my macro that opens a workbook in one folder and copies the contents to a workbook in another folder.

    When this runs, the dates in Col A change the format from dd/mm/yyyy to mm/dd/yyyy. I am really not sure why this happens and I have tried everything, including using local:=true when opening the workbook and also forcing the format by adding: selection.numberformat= "dd/mm/yyyy" but nothing seems to work??

    Can anyone help me with this problem? Attached are the two worksheets I am using and also the macro is here:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    can anyone please assist me with this problem

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    cant test your code, but maybe if you make that text real dates with text to columns?

    Please Login or Register  to view this content.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    thanks scottiex. How would I insert that into my code, assume it goes here:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    I tried the following but it isn't working??

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    the dates still get copied across in the opposite format, i.e. they show in the initial worksheet as dd/mm/yyyy but when copied become mm/dd/yyyy?

  7. #7
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    the dates still get copied across in the opposite format, i.e. in the initial spreadsheet they show as dd/mm/yyyy but when copied show as mm/dd/yyyy?

  8. #8
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    I meant convert it to an actual date before you copy it. You could even convert it to a number as well then convert it back if it is still an issue.

  9. #9
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    thanks scottiex.

    I put the code here but still the same

    Please Login or Register  to view this content.

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Please Login or Register  to view this content.
    does the issue still occur with just this bit of code? as in the test example it does not have this issue
    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.

  11. #11
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    yes it does humdingaling.

    Are you saying you ran the initial code above and you didn't have any issues?

  12. #12
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    could that be because you are adding a workbook in your test code rather than opening a workbook in another folder?

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Because your "dates" are not date, just string.

  14. #14
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    thanks jindon,

    How can you tell they are just strings? Are they all strings? How could I go about resolving my problem if they are strings?

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    correct
    i have no issues running this with both your sample file

    however i have found the issue
    let me do a few tests and ill come back with workaround

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    If it is date it appears like yyyy/m/d in formula bar, but it is now 11/05/2016.

    1) select column - [Date] - [TextToColumns] -[Next] - [Next]
    2) select [Date] select "MDY" from the dropdown [Finish]

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    ok the issue is the closing of the file before pasting

    Please Login or Register  to view this content.
    tested using this code

    if you close the workbook after the pasting it doesnt seem to have the issue anymore
    Last edited by humdingaling; 06-21-2017 at 01:37 AM. Reason: tidy up the code..added more comments

  18. #18
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    thanks a lot humdingaling.

    I adjusted my initial code to the below but I get a run time error because the workbook is already open (the workbooks have the same name but in different folders so do I need to adjust further?

    Please Login or Register  to view this content.

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    you need to declare and set Wb in order to use it

    Please Login or Register  to view this content.
    Last edited by humdingaling; 06-21-2017 at 02:16 AM. Reason: left out the e

  20. #20
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    oh ok, I didn't know that. How can I amend the code for that?

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    already did on the code provided ...i changed to be in red so it stands out

    does it still not work?

  22. #22
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    sorry didn't see it. Will try it now.

  23. #23
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Please Login or Register  to view this content.
    Needed to make the changes in red but now I get an automation error so perhaps I haven't done it right??

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    You guys have no idea about the meaning of the code why it must close before it opens other workbook.

    https://www.excelforum.com/excel-pro...n-another.html

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    sorry i forgot to add the with WB in my previous code

    Please Login or Register  to view this content.

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Jindon:
    my response is to the particular problem of the date switching from Australian standard (DD/MM/YYYY) to US standard (MM/DD/YYYY)

    as i have the same date settings at OP, i was able to replicate the OP issue with the code in post #17
    if the workbook it copies from is open closed before it opens pastes into new workbook

    the issue occurs
    closing the original workbook of which the data is copied from after pasting seems to circumvent this from happening (don't know the exact reasoning this happens...chalk it up to another MS quirk with dealing with dates in VBA environment)

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    It is not my original code, but the data itself, so I have posted the solution in #16.

    It will be impossible to solve the issue unless convert string date to serial date.

  28. #28
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Please Login or Register  to view this content.
    Still get a run time error on the line highlighted above saying file is already open??

  29. #29
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857
    Quote Originally Posted by jindon View Post
    It is not my original code, but the data itself, so I have posted the solution in #16.

    It will be impossible to solve the issue unless convert string date to serial date.
    Thanks jindon. I am not sure how I would convert the string date to serial date and incorporate in the code you gave me.

    Could you please assist me with this?

    Thank you!

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    You guys have no idea about the meaning of the code why it must close before it opens other workbook.
    i see the problem with my solution now...cannot have the two files with the same name open at once

    ill give it another whirl tomorrow unless someone else thinks of something that works for you prior
    the method to circumvent the problem still works....just need to get around this issue of having two files with the same name

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Please Login or Register  to view this content.

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Jindon: tested your code a few times...i still get the same issue that OP faces
    the dates switch from AU standard to US standard

    Please Login or Register  to view this content.
    added a "dump" workbook in the middle so main wb can close in order for the sub wb to be opened

  33. #33
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Quote Originally Posted by humdingaling View Post
    Jindon: tested your code a few times...i still get the same issue that OP faces
    the dates switch from AU standard to US standard

    Please Login or Register  to view this content.
    added a "dump" workbook in the middle so main wb can close in order for the sub wb to be opened
    jindon, the same thing happened to me. It still switches from AU format to US format.

    humdingaling, I tried your code and although it worked, when I went to sort the data, it asked me if it wanted to sort numbers that look like numbers, so I wonder if some of the dates are still text and how to fix this?

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    Which my code are you talking about?

  35. #35
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    I used a combination of both of these and it managed to work using this:

    Please Login or Register  to view this content.
    I am going to keep testing to see if it continues.

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

    Re: Strange Problem - Copy paste dates changes format from dd/mm/yyyy to mm/dd/yyyy

    i got that text message when sorting as well

    it looks like you have managed to amalgamate a solution up
    its what i would have done

+ 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: 8
    Last Post: 10-02-2013, 06:23 PM
  2. Replies: 7
    Last Post: 11-18-2012, 02:28 PM
  3. Replies: 0
    Last Post: 10-14-2012, 05:48 PM
  4. [SOLVED] Imported data contains strings dd.mm.yyyy how can I convert to date format dd/mm/yyyy inVB
    By Boormo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-05-2012, 05:48 PM
  5. Copy+Paste macro dd/mm/yyyy to dd/mm/yyyy and NOT dd/mm/yyyy to mm/dd/yyyy
    By uimhirADo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2012, 03:45 AM
  6. Macro to convert dates format from yyyy mm dd to yyyy-mm-dd
    By Gators in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 02-26-2009, 02:23 PM
  7. Date problem when opening a csv with dates in dd-mm-yyyy format.
    By Jeroen Hofs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2005, 05:05 AM
  8. [SOLVED] opening excel file -> date format problem: DD/MM/YYYY vs MM/DD/YYYY
    By yung in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2005, 09:06 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