Hi
I know about the classic problem of VBA seeing a date that was in format dd/mm/yyyy and treating it as mm/dd/yyyy instead.
But I've developed 2 macros for manipulating different sets of data and I'm puzzled why one of the macros is being affected by this whilst the other macro isn't.
Dim HistoryArray() as variant
.....
.....
Redim HistoryArray(1 to xxx, 1 to yyy)
Macro 1
Column I & J of the worksheet have cells formatted as *14/03/2012. Those cells contain formulas that result in dates.
Some of those dates are uploaded into the HistoryArray one at a time.
Those dates that were uploaded, plus other data items, are then pasted into another worksheet:
There are no calculations or comparisons of dates done in the VBA
Those values are appearing in the output in *14/03/2012 format, just like I want
Macro 2 (Note: Transpose is involved in this because I would have wanted the number of rows in the results array to be dynamic, but you can only redim the second dimension)
Columns P and Q have cells formatted as *14/03/2012. Those cells contain formulas that result in dates.
Columns F and G have cells formatted as custom dd-mm-yyyy. Those cells contain raw data values (that's the format of the raw data).
It sorts the worksheet by column F
All data is uploaded into HistoryArray via a transpose operation
Using the array, it does comparisons between the dates that were taken from P,Q,F,G and outputs the relevant ones into a ResultsArray
The ResultsArray is then pasted onto another worksheet via a transpose operation
Some dates are appearing in the results as e.g. 01/04/2016 when they should be 04/01/2016
So why is one macro doing this unwanted editing of dates whereas the other macro doesn't?
Is it the transpose that is making the difference?
I've got around this problem with Macro 2 by making the macro format all dates as .NumberFormat = "0" on the worksheet before uploading them to the array, then re-format them back as dd/mm/yyyy when its finished.
I'm feeling like I need to do the same with Macro 1 just to be safe. But it's bugging me why wasn't this a problem with Macro 1?
Thanks
I know about the classic problem of VBA seeing a date that was in format dd/mm/yyyy and treating it as mm/dd/yyyy instead.
But I've developed 2 macros for manipulating different sets of data and I'm puzzled why one of the macros is being affected by this whilst the other macro isn't.
Dim HistoryArray() as variant
.....
.....
Redim HistoryArray(1 to xxx, 1 to yyy)
Macro 1
Column I & J of the worksheet have cells formatted as *14/03/2012. Those cells contain formulas that result in dates.
Some of those dates are uploaded into the HistoryArray one at a time.
Those dates that were uploaded, plus other data items, are then pasted into another worksheet:
Code:
OutputSheet.Range(Cells(1,1), Cells(RowsRequired,4)) = HistoryArray
Those values are appearing in the output in *14/03/2012 format, just like I want
Macro 2 (Note: Transpose is involved in this because I would have wanted the number of rows in the results array to be dynamic, but you can only redim the second dimension)
Columns P and Q have cells formatted as *14/03/2012. Those cells contain formulas that result in dates.
Columns F and G have cells formatted as custom dd-mm-yyyy. Those cells contain raw data values (that's the format of the raw data).
It sorts the worksheet by column F
All data is uploaded into HistoryArray via a transpose operation
Code:
HistoryArray = Application.WorksheetFunction.Transpose(Sheets("History").Range("A1:Q" & LastRow).Value)
The ResultsArray is then pasted onto another worksheet via a transpose operation
Code:
OutputSheet.Range("A1").Resize(RowsRequired,11) = Application.WorksheetFunction.Transpose(ResultsArray)
Some dates are appearing in the results as e.g. 01/04/2016 when they should be 04/01/2016
So why is one macro doing this unwanted editing of dates whereas the other macro doesn't?
Is it the transpose that is making the difference?
I've got around this problem with Macro 2 by making the macro format all dates as .NumberFormat = "0" on the worksheet before uploading them to the array, then re-format them back as dd/mm/yyyy when its finished.
I'm feeling like I need to do the same with Macro 1 just to be safe. But it's bugging me why wasn't this a problem with Macro 1?
Thanks