+ Reply to Thread
Results 1 to 7 of 7

Date Day and Month Reverse When Copying Data from a Range To A Table using an Array

  1. #1
    Forum Contributor
    Join Date
    04-23-2014
    Location
    Liverpool...ish
    MS-Off Ver
    Excel 2013
    Posts
    126

    Date Day and Month Reverse When Copying Data from a Range To A Table using an Array

    I have a problem where I pass a range, of which one cell is a date (formated DD/MM/YYYY) to an array . The array then pastes to a table row. The date however has the DAY and MONTH transposed.

    Any insight as to why this is happening, I would appriciated it.

    ReverseDateExp.xlsm

    Regards
    Scott
    Last edited by TheScott; 05-29-2015 at 09:53 AM.

  2. #2
    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
    49,445

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using and Array

    It's because the worksheet uses Regional Settings for dates but VBA is American through and through.

    Given the nature of the specific example, I'd just go with:

    Please Login or Register  to view this content.

    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


  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using and Array

    The F column is formatted as Custom (mmm.yyyy). Select the whole column and format it as short date.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Forum Contributor
    Join Date
    04-23-2014
    Location
    Liverpool...ish
    MS-Off Ver
    Excel 2013
    Posts
    126

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using and Array

    TMS Humm….. OK, I understand what you are saying but something is lost in my understanding of Excel and how it processes dates. It has been my understanding that if you were to format a cell as dd/mm/yyyy and another as mm/dd/yyyy and entered the same date(following the appropriate format), the underlying number that Excel uses to process dates would be the same…. Is this not true?

    I appreciate the fix to this application but I am not sure I can use it elsewhere without a better understanding of dates and arrays and what happens to them when they cross that excel / vba threshold. Any insight would be appricated.

    Bulina2k - I attemped to format the entire F column... and just the cells within the table in a variety of ways. I used the custom MMM/YY because it was just easier to see the date problems for this example. no matter what format is used in the f column if you put a date in B4 (which is formatted dd/mm/yyy) which starts with any number over 12... you get a text entery in column F.

    Regards
    Scott
    Last edited by TheScott; 05-29-2015 at 09:36 AM.

  5. #5
    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
    49,445

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using an Array

    I think that, be default, you are copying the date as shown in the cell, that is the Regional, as displayed, date. That is then processed in VBA and, when pushed back out, you're getting the American version.

    Try using Value2 instead of defaulting to Value

    Please Login or Register  to view this content.

    As far as I understand, Value2 will give you the underlying numeric value and, consequently, it will not get massaged in the transition.


    Regards, TMS

  6. #6
    Forum Contributor
    Join Date
    04-23-2014
    Location
    Liverpool...ish
    MS-Off Ver
    Excel 2013
    Posts
    126

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using an Array

    Thumbs Up! Learned something new and that can't be bad. I appreciate your help!

    As an added thought for others who might stumble on this thread. I had thought that using the .Value2 when applied to the entire array might cause errors with cells containing underlying formulas but as far as I can tell, it does not and will paste the value obtained by the calculations....

    Regards and Thanks

    Scott
    Last edited by TheScott; 05-29-2015 at 10:27 AM.

  7. #7
    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
    49,445

    Re: Date Day and Month Reverse When Copying Data from a Range To A Table using an Array

    A little more information ... https://fastexcel.wordpress.com/2011...w-to-avoid-it/


    Range.Value2

    This works the same way as Range.Value, except that it does not check the cell format and convert to Date or Currency.

    And, just for fun:

    Please Login or Register  to view this content.

    Regards, TMS

+ 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. Array function for date(month), Range Date(month)
    By dluhut in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-19-2013, 05:14 PM
  2. Replies: 2
    Last Post: 07-06-2012, 02:38 PM
  3. how to reverse a range/array?
    By peter dmz in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-06-2005, 04:05 PM
  4. how to reverse a range/array?
    By peter dmz in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  5. how to reverse a range/array?
    By peter dmz in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 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