Sorting Multiple Columns in a single operation?

A

Andy Hulse

We have collected approx 100 pieces of info on 250 students, each held
student id being the column header and the data held in that column. We want
to be able to select all the data and to be able to sort each column into
ascending or descending order, independently of the other columns in a single
opeation. (i.e. the equivalent of selecting each column of data, sorting it,
then selecting the next etc., until all hav been slected and sorted). Can
anyone suggest how this may be done, is there a VBA script out there that can
do this?
 
M

merjet

The following does 4 columns and assumes the same number of rows in
each column. You can easily modify it to suit.

Sub Macro1()
Dim iEnd As Integer
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
iEnd = ws.Range("A1").End(xlDown).Row
For iCol = 1 To 4
ws.Range(Cells(1, iCol), Cells(iEnd, iCol)).Sort Key1:=Cells(2,
iCol), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next iCol
End Sub

Hth,
Merjet
 
A

Andy Hulse

Thanks a lot for this, with a bit of fiddling I have managed to get it to do
just what I needed.

Great and thanks once again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top