ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting on more than one column (https://www.excelbanter.com/excel-programming/398320-sorting-more-than-one-column.html)

Jock

Sorting on more than one column
 
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!!

--
Traa Dy Liooar

Jock

Matthew Pfluger

Sorting on more than one column
 
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

"Jock" wrote:

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!!

--
Traa Dy Liooar

Jock


Gary Keramidas

Sorting on more than one column
 

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

--


Gary


"Jock" wrote in message
...
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!!

--
Traa Dy Liooar

Jock




Brian

Sorting on more than one column
 
On Sep 28, 10:10 am, Jock wrote:
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!!

--
Traa Dy Liooar

Jock


Either

choose DataSort... 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
---



All times are GMT +1. The time now is 06:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com