Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multiple column sorting

531 views
Skip to first unread message

Dave

unread,
Apr 20, 2001, 12:05:20 PM4/20/01
to
Does anyone know how to sort say 6 columns at a time?

Wilson

unread,
Apr 20, 2001, 12:16:05 PM4/20/01
to
I don't know if you can sort more than 3 in VBA, but you should be able to
get the desired results doing 4 successive sorts of 3 columns, if you're
clever about the order in which you do the sorts.
FWIW
"Dave" <doyo...@whatever.com> wrote in message
news:481a01c0c9b3$b2e7ab70$9ee62ecf@tkmsftngxa05...

JPN

unread,
Apr 20, 2001, 2:28:03 PM4/20/01
to
Hi Dave,

If you want sort all columns based on one column then you can you use this
sub here. (Modified by Tom Ogilivy)
Sorting is based on the "SortColumn" variable.

Regards,
JPN

Sub demo()
Dim temp As Variant
Dim LastColumn As Integer
Dim LastRow As Long
Dim SortColumn As Integer

SortColumn = 1
LastColumn = Cells(1, 256).End(xlToLeft).Column
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
vArr = Range(Cells(1, 1), Cells(LastRow, LastColumn))
For i = 1 To LastRow
For j = i + 1 To LastRow
If vArr(i, SortColumn) > vArr(j, SortColumn) Then
For k = LBound(vArr, 2) To UBound(vArr, 2)
temp = vArr(i, k)
vArr(i, k) = vArr(j, k)
vArr(j, k) = temp
Next
End If
Next j
Next i
Range(Cells(1, 1), Cells(LastRow, LastColumn)).Value = vArr
End Sub


Dave <doyo...@whatever.com> wrote in message
news:481a01c0c9b3$b2e7ab70$9ee62ecf@tkmsftngxa05...

Dave

unread,
Apr 20, 2001, 2:51:26 PM4/20/01
to
Thanks for the code! Perfect.;
-----Original Message-----
Hi Dave,

Regards,
JPN


.

0 new messages