+ Reply to Thread
Results 1 to 6 of 6

VBA messing up date formats

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Post VBA messing up date formats

    Hi All,
    This is the code:
    Please Login or Register  to view this content.
    The code at first sight does what I wanted it to do. However at a closer look....
    So it copies data from a source to a new destination workbook.
    Now in this source there are also date and they look like :
    30/9/2013
    30/9/2013
    30/9/2013
    1/10/2013
    1/10/2013
    1/10/2013
    2/10/2013
    2/10/2013
    This is 30 september, 1 october and 2 october which is correct

    However after pasting it the dates look suddenly like
    30/9/2013
    30/9/2013
    30/9/2013
    10-1-2013
    10-1-2013
    10-1-2013
    10-2-2013
    10-2-2013
    Now I have 20 september 10 januari and 10 february!!

    What happend?! And better yet...how to fix this?
    PS: As you can see I already blocked the replacement of "/" to "." and that is how I saw that error arose during the copy/paste action.
    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: VBA messing up date formats

    Hi
    This looks like you have different date formatting in different cells on your destination worksheet. Make sure that the destination worksheet range is set to the same format as the source cells. The October cells appear to be formatted as US date format.
    Good luck.
    Tony

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA messing up date formats

    Hi Thanks, but the destination worksheet is a clean newly generated workbook by the first part of the code.
    So would not be possible that the destination sheet has multiple cell fomats in it.

  4. #4
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA messing up date formats

    Well if I first convert the "/" to "." before I copy/past then I do have the correct dates...but..... Now excel thinks its text.
    It will lineout to the left. And as I have in another cell a formula which pulls the weeknumber from that "Date" I get a formula error because it does not see 1.10.2013 as a date.
    So if somebody knows how to fix that that also would help!

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA messing up date formats

    Nobody??
    It would also help if someone can tell me vba to format data in several date formats....

  6. #6
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: VBA messing up date formats

    Hi
    Can you post a sample of your source worksheet with your code.
    Tony

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA messing up date formats

    perhaps replace
    Please Login or Register  to view this content.
    by
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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. Default Cell Format is Date = Messing up Pivot Table!
    By yoyoma123 in forum Excel General
    Replies: 2
    Last Post: 09-23-2011, 09:28 AM
  2. Date Formats
    By MPanter in forum Excel General
    Replies: 2
    Last Post: 12-07-2010, 09:26 AM
  3. European vs. American date formats messing up autosort
    By theradpotato in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-07-2010, 02:11 PM
  4. US to UK Date Formats
    By reggie1000 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-22-2009, 10:49 AM
  5. Date formats
    By Hervinder in forum Excel General
    Replies: 3
    Last Post: 04-19-2006, 08:25 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