Texas Longhorn
Active Member
- Joined
- Sep 30, 2003
- Messages
- 493
Hi All,
I have a worksheet with a few hundred columns of data. The data is paired in groups of two columns with equal rows (i.e. Columns A and B have 1000 rows, Columns C and D havd 990 rows, Columns E and F have 1115 rows, etc...they're paired). I'm trying to write some code to sort each two-column group by the pair's second column (i.e. Sort A1:B1000 by values in column B; sort C1:D990 by values in column D; sort E1:F1115 by values in column F, etc).
I wrote the following which highlights an error with the Sort line.
Any help would be much appreciated.
Thanks,
Bill
I have a worksheet with a few hundred columns of data. The data is paired in groups of two columns with equal rows (i.e. Columns A and B have 1000 rows, Columns C and D havd 990 rows, Columns E and F have 1115 rows, etc...they're paired). I'm trying to write some code to sort each two-column group by the pair's second column (i.e. Sort A1:B1000 by values in column B; sort C1:D990 by values in column D; sort E1:F1115 by values in column F, etc).
I wrote the following which highlights an error with the Sort line.
Code:
Sub SortByGroup()
'Application.ScreenUpdating = False
For i = 1 To 367
ActiveCell.Range("A1:B1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key1:=Range("B1"), Order:=xlAscending, Header:=xlYes
Selection.Offset(0, 2).Activate
Next i
'Application.ScreenUpdating = True
End Sub
Any help would be much appreciated.
Thanks,
Bill