Hi all, trying to sort dates and events on those dates which are in two rows like so:
[TABLE="width: 500"]
<tbody>[TR]
[TD]4/2/2016[/TD]
[TD]6/3/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD]7/7/2015[/TD]
[TD][/TD]
[TD][/TD]
[TD]1/2/2016[/TD]
[TD]6/6/2016[/TD]
[TD]6/15/2016[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]AAA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]CCC[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
These rows continue for hundreds of columns, and there are hundreds of row pairings themselves.
Some of the dates have events, others are blanks.
There are some blanks between dates as well.
>Selecting two rows together at a time sorts the row pairs together and keeps the second row events together with their corresponding date.
No problem with empties or anything- Easy enough.
IE the Sort Yields:
[TABLE="width: 500"]
<tbody>[TR]
[TD]7/7/2015[/TD]
[TD]1/2/2016[/TD]
[TD]4/2/2016[/TD]
[TD]6/3/2016[/TD]
[TD]6/6/2016[/TD]
[TD]6/15/2016[/TD]
[/TR]
[TR]
[TD]AAA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]CCC[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
My question is- how can I automate this two row a piece simple sorting down the entire selection of data/or sheet,
instead of having to select each set of two rows manually?
I tried recording a macro but found I'd have to manually change the selections in it too ex:
I suppose the solution would be to get rid of the select code and do some looping, but I can't get it to work.
Any help is MUCH appreciated!
[TABLE="width: 500"]
<tbody>[TR]
[TD]4/2/2016[/TD]
[TD]6/3/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD]7/7/2015[/TD]
[TD][/TD]
[TD][/TD]
[TD]1/2/2016[/TD]
[TD]6/6/2016[/TD]
[TD]6/15/2016[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]AAA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]CCC[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
These rows continue for hundreds of columns, and there are hundreds of row pairings themselves.
Some of the dates have events, others are blanks.
There are some blanks between dates as well.
>Selecting two rows together at a time sorts the row pairs together and keeps the second row events together with their corresponding date.
No problem with empties or anything- Easy enough.
IE the Sort Yields:
[TABLE="width: 500"]
<tbody>[TR]
[TD]7/7/2015[/TD]
[TD]1/2/2016[/TD]
[TD]4/2/2016[/TD]
[TD]6/3/2016[/TD]
[TD]6/6/2016[/TD]
[TD]6/15/2016[/TD]
[/TR]
[TR]
[TD]AAA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]CCC[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
My question is- how can I automate this two row a piece simple sorting down the entire selection of data/or sheet,
instead of having to select each set of two rows manually?
I tried recording a macro but found I'd have to manually change the selections in it too ex:
Code:
Sub TestOrder()
'
' TestOrder Macro
'
'
Rows("1:2").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1:NU1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:NU2")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Rows("3:4").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A3:NU3") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A3:NU4")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Rows("5:6").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A5:NU5") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A5:NU6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
I suppose the solution would be to get rid of the select code and do some looping, but I can't get it to work.
Any help is MUCH appreciated!