Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
I have taken over a spreadsheet and macro that a previous colleague built for a regular report that I am required to run for my team. The report works great with one exception – certain dates appear to be impacted when the day is 1 to 12 (inclusive), in that the days and month swap around. Up until now, I have been manually amending this each week, but as the data grows, this is becoming more and more time consuming.<o></o>
<o></o>
Basics of what I am doing:<o></o>
· I extract data via a system that exports it in a CSV file – dates are in the format of DD/MM/YY<o></o>
· I paste the data into my s/sheet and then run the below macro over it – this merges the columns and puts everything into its own columns so that it can be easily pivoted from<o></o>
· There are several columns that are dates – any date that is from day 13 or above i.e. 13/06/11 remains correct (DD/MM/YY), however, if the date is 03/06/11 once the macro is run, it formats the date as 6/03/2011. So, it not only sways the day and month around, but also changes the year to being 4 digits.<o></o>
<o></o>
Public Sub mergeColumns()<o></o>
<o></o>
Dim paste_point As Range<o></o>
<o></o>
Dim keep_row As Integer<o></o>
Dim merge_row As Integer<o></o>
Dim keep_columns As Integer<o></o>
Dim merge_columns As Integer<o></o>
<o></o>
Dim keep_array As Variant<o></o>
Dim merge_array As Variant<o></o>
Dim merge_column_array As Variant<o></o>
<o></o>
' Arrays for storing all the data we wish to copy<o></o>
keep_array = Range(Range("$F$1").Value).Value<o></o>
merge_array = Range(Range("$F$2").Value).Value<o></o>
merge_column_array = ArrayFunctions.ArrayTranspose(ArrayFunctions.SubArray(merge_array, 1, UBound(merge_array, 2), 1, 1))<o></o>
<o></o>
keep_columns = UBound(keep_array, 2)<o></o>
merge_columns = UBound(merge_column_array, 1)<o></o>
<o></o>
Set paste_point = Range(Range("$F$3").Value)<o></o>
<o></o>
Application.ScreenUpdating = False<o></o>
Application.DisplayAlerts = False<o></o>
Application.StatusBar = False<o></o>
Application.Calculation = xlCalculationManual<o></o>
<o></o>
For keep_row = 1 To UBound(keep_array, 1)<o></o>
<o></o>
merge_row = merge_columns * (keep_row - 1)<o></o>
<o></o>
paste_point.Offset(merge_row, 0).Resize(merge_columns, keep_columns).Value = Application.WorksheetFunction.Index(keep_array, keep_row, 0)<o></o>
<o></o>
paste_point.Offset(merge_row, keep_columns).Resize(merge_columns, 1).Value = merge_column_array<o></o>
<o></o>
paste_point.Offset(merge_row, keep_columns + 1).Resize(merge_columns, 1).Value = ArrayFunctions.ArrayTranspose(ArrayFunctions.SubArray(merge_array, 1, UBound(merge_array, 2), keep_row + 1, keep_row + 1))<o></o>
<o></o>
Next keep_row<o></o>
<o></o>
Application.ScreenUpdating = True<o></o>
Application.DisplayAlerts = True<o></o>
Application.StatusBar = True<o></o>
Application.Calculation = xlCalculationAutomatic<o></o>
<o></o>
End Sub<o></o>
<o></o>
I am not that great with macros and would sincerely appreciate any help! : ) <o></o>
<o></o>
I have taken over a spreadsheet and macro that a previous colleague built for a regular report that I am required to run for my team. The report works great with one exception – certain dates appear to be impacted when the day is 1 to 12 (inclusive), in that the days and month swap around. Up until now, I have been manually amending this each week, but as the data grows, this is becoming more and more time consuming.<o></o>
<o></o>
Basics of what I am doing:<o></o>
· I extract data via a system that exports it in a CSV file – dates are in the format of DD/MM/YY<o></o>
· I paste the data into my s/sheet and then run the below macro over it – this merges the columns and puts everything into its own columns so that it can be easily pivoted from<o></o>
· There are several columns that are dates – any date that is from day 13 or above i.e. 13/06/11 remains correct (DD/MM/YY), however, if the date is 03/06/11 once the macro is run, it formats the date as 6/03/2011. So, it not only sways the day and month around, but also changes the year to being 4 digits.<o></o>
<o></o>
Public Sub mergeColumns()<o></o>
<o></o>
Dim paste_point As Range<o></o>
<o></o>
Dim keep_row As Integer<o></o>
Dim merge_row As Integer<o></o>
Dim keep_columns As Integer<o></o>
Dim merge_columns As Integer<o></o>
<o></o>
Dim keep_array As Variant<o></o>
Dim merge_array As Variant<o></o>
Dim merge_column_array As Variant<o></o>
<o></o>
' Arrays for storing all the data we wish to copy<o></o>
keep_array = Range(Range("$F$1").Value).Value<o></o>
merge_array = Range(Range("$F$2").Value).Value<o></o>
merge_column_array = ArrayFunctions.ArrayTranspose(ArrayFunctions.SubArray(merge_array, 1, UBound(merge_array, 2), 1, 1))<o></o>
<o></o>
keep_columns = UBound(keep_array, 2)<o></o>
merge_columns = UBound(merge_column_array, 1)<o></o>
<o></o>
Set paste_point = Range(Range("$F$3").Value)<o></o>
<o></o>
Application.ScreenUpdating = False<o></o>
Application.DisplayAlerts = False<o></o>
Application.StatusBar = False<o></o>
Application.Calculation = xlCalculationManual<o></o>
<o></o>
For keep_row = 1 To UBound(keep_array, 1)<o></o>
<o></o>
merge_row = merge_columns * (keep_row - 1)<o></o>
<o></o>
paste_point.Offset(merge_row, 0).Resize(merge_columns, keep_columns).Value = Application.WorksheetFunction.Index(keep_array, keep_row, 0)<o></o>
<o></o>
paste_point.Offset(merge_row, keep_columns).Resize(merge_columns, 1).Value = merge_column_array<o></o>
<o></o>
paste_point.Offset(merge_row, keep_columns + 1).Resize(merge_columns, 1).Value = ArrayFunctions.ArrayTranspose(ArrayFunctions.SubArray(merge_array, 1, UBound(merge_array, 2), keep_row + 1, keep_row + 1))<o></o>
<o></o>
Next keep_row<o></o>
<o></o>
Application.ScreenUpdating = True<o></o>
Application.DisplayAlerts = True<o></o>
Application.StatusBar = True<o></o>
Application.Calculation = xlCalculationAutomatic<o></o>
<o></o>
End Sub<o></o>
<o></o>
I am not that great with macros and would sincerely appreciate any help! : ) <o></o>