Sorting on more than one column

J

Jock

How can I sort numbers from 1-7 in column 'C' ascending and then sort the
dates in column 'A' in descending order for each group of numbers in 'C' with
one piece of code?

A C
15/08 2
14/08 3
16/08 2
17/08 3
16/08 3
15/08 1

Hope that makes sense!!
 
M

Matthew Pfluger

Try this:

Range("A1:C7").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("A2")
, Order2:=xlDescending, Header:=xlYes

You may have to change "Range("A1:C7")" to fit your data range.

HTH,
Matthew Pfluger
 
G

Gary Keramidas

maybe something like this:

Sub sort_cols()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws.Range("A1:C7")
.Sort Key1:=ws.Range("C1"), Order1:=xlAscending, Key3:=ws.Range("A1") _
, Order3:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption3 _
:=xlSortNormal
End With
End Sub
 
B

Brian

How can I sort numbers from 1-7 in column 'C' ascending and then sort the
dates in column 'A' in descending order for each group of numbers in 'C' with
one piece of code?

A C
15/08 2
14/08 3
16/08 2
17/08 3
16/08 3
15/08 1

Hope that makes sense!!

Either

choose Data>Sort... and choose "Column C" (ascending) and 'then by'
"Column A" (descending)

or code:

Range("A1:C6").Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending,
Key2:=Range("A1") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom

Brian Herbert Withun
---
 

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