When I transpose a 1 dimensional array, containing dates, in order to print them to a sheet in it\'s entirety, some dates are changed from the dd/m
I hit this problem, but interestingly, the date switch (from dd/mm to mm/dd) on transpose only happened when I ran the macro from a toolbar button; if I ran it from inside the VBA editor, or from the Developer menu>Macros dialogue box, it worked fine. To make it work no matter where I ran the macro from, I added a function before the transpose to convert all dates to strings (looping through my array and using the CStr function), and then converted back from strings to dates after the transpose (another loop and CDate function) - the loops having to be slightly different to account for the transposed dimensions.
After doing some more research, I have found the following:
It would seem that the Application.Transpose(arrDate)
transposes not only the array, but also date values when they are stored as actual date.
Consider the date , 42373
(January 4, 2016)
Debug.Print Format(CDate(42373), "mmmm d, yyyy")
januari 4, 2016
Debug.Print Application.Transpose(Format(CDate(42373), "mmmm d, yyyy"))
april 1, 2016
It appears that a date value can be transposed when stored as an actual date. The transposing effectively reorders the date from day/month
to month/day
after which the the month becomes the day and the day becomes the month because the system still uses the day/month
format. This can only be done if the day of the month is 12 or less, because after transposing the day becomes the month.
Transposing array with Application.Transpose() transforms the "Date" data type into "String". Not able to explain why. So my suggestion is to transform the Column with "Date" data type into "Long" before you do the Application.Transpose() (simply using CLng). After that you can either transform it back to "Date" or just set the number format as "Date" for the cells, where you would like to paste the array.