Variable sorting

G

Graham H

In Excel 2003 I have a range A15 to U500. In column B there will be either the text value
P or S. I want to do a sort on the range which will involve 4 criteria. To achieve this I
want to sort column B to order the P and S. I then want to select the rows with P and sort
by the three other criteria. I then need the rows below these with S and sort by the same
criteria. I have a schematic below of what I was trying but my problem is in selecting the
row range or how best to do it. eg below I was trying-- rows ("15:14+a").select ---but
this is obviously not the way to do it. There may be and probably is a better way to do
the whole thing but I would value any help.

Sub sorting()
Dim n As Integer
a = 0
For n = 15 To 500
If Cells(n, 2) > 0 Then
a = a + 1
End If
Next'<< selection sort by column 2 I can do this
b = 0
For n = 15 To 500
If Cells(n, 2) = "P" Then
b = b + 1
End If
Next'<< selection sort by columns 3 7 and 8 I can do this
End Sub

Graham
 

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