Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2010 VBA problem with sort key1=ascending, key2=descending

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
I've just used this to sort my data first ascending (row number column), then descending (name column):

Code:
Set WS = wb1.Worksheets(vGroupName)
Set rSortRange = WS.Range(vColumnLetterToSortGroupBy2 & "1")
rSortRange.Sort Key1:=WS.Range(wb1EndColLetterPlus1vGroupName & "1"), Order1:=xlAscending, _
                Key2:=WS.Range(vColumnLetterToSortGroupBy2 & "1"), Order2:=xlDescending, _
                Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
                Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
                DataOption2:=xlSortNormal ', DataOption3:=xlSortNormal

Unfortunately the descending part dosn't work, the output is in ascending order.

I have also just tried doing this manually and it dosn't work either!

Any advice on what I may be doing wrong would be much appreciated.
Kind regards,
Roy

 
Please post a sample of the data in these 2 columns with SORTED results.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
The data is below and it couldn't be more straightforward. I'm trying to sort first by heading (ASC), then by person (DESC).
I can sort descending when I do a first level sort. But the second level dosn't work at all.

Am I getting something very basic wrong??

Thanks for your help,
Roy

Person Heading
Aditya, ROY1 2
Aibino, Cristina 3
Andrews, Mallory 4
Berlin, Ellie 5
Blum, Jackie 6
Burd, Candice 7
Carfrae, Malcolm 8
Daley, William 9
D'Antonio, Elisabeth 10
Drell Szyfer , Elana 11
Emeruwa, Erika 12
Feinberg, Jennifer 13
Ferrara, Michael 14
Gaynor, Josh 15
Graham, Tanner 16
Greenwald, Ellen 17
Hoffmeister, Stacie 18
Kalman, Michael 19
Khalid, Lubna 20
Klein, Beth 21
Lange, Emily 22
Lawson, Blair 23
Murphy, Johanna 24
Nachman, Robert 25
Porgis, Alex 26
Rousseau, Gilles 27
Ryan, Michelle 28
Schechter, Michael 29
Sebelle, Kristin 30
Shipp, Brandi 31
Sillard, Amelia 32
Terker, Jane 33
Touchton, Jill 34
Vitali, Matteo 35
Weisenfeld, Jason 36
Wells, Jessica 37
Wilson-Gray, Sheri 38
Zarkin, Douglas 39
Aguilar, Marlene 40
Henderson, Stacie 41
Hinds Banfe, Kathy 42
Kronengold, Vivien S. 43
Molinaro, Shanin 44
Spatz, Abby 45
Andrew, Kyle 46
Andrews, Joe 47
Bacal, Amanda McCormick 48
Baldwin, Amanda G. 49
Berthod, Annette 50
Brenner, Marjorie 51
Burkhardt, Thomas A. 52
Carey, Liz 53
Chokachi, Susan 54
Cutter, Michelle 55
Dadoul, Sarra 56
D'Arminio, Michael 57
Dennis, Jessica 58
Gers, Dana 59
Hayes, Karen 60
Hellman, Lisa 61
Henkel, Lisa 62
Hong, Jennifer 63
Incandela, Denise 64
Knaak-Stuart, Lindsay 65
Kolasa, George 66
Kramer, Stephanie D. 67
Krauss, Lori 68
Lamont, Elizabeth 69
Lewis, Anjali 70
Lilly, Cristina 71
Mankin, Elizabeth 72
Manley, Sarah 73
Mould, Damian 74
Pomerantz, Lisa 75
Raines, Heidi 76
Sabnani, Vanita 77
Shukla, Siddhartha 78
Sontag, Alicia 79
Stasko, Melisa 80
Sullivan, Kate 81
Thomas, Magali 82
Tomasello, Valerie 83
Twist, Kate 84
Vandenberghe, Heather 85
Wagner, Lori 86
Wright, Ginny 87
Andriani, Gustavo 88
Ascher, Kendal 89
Berthold, Corinna 90
Bond, Emily 91
Buckley, Kristina 92
Calcagni, Barbara 93
Campbell, Kristen 94
DeLellis, Michael 95
Doddy, Patrick 96
Downs, Denny 97
Emmett, Geri 98
Ettinger, Robin 99
Gladel, Peter 100
Iacuzzo, Christine 101
Jehan, Aurelien 102
Jesel, Guillaume 103
Landau, Agnes 104
Lien, Ada 105
Lloreda, Claudia 106
Moudachirou-Rébois, Aïda 107
Rothstein, Sharon 108
Rubinfeld, Emilie 109
Singer, Lori 110
Speichert, Marc 111
Truffelman Macune, Meryl 112
Weiss, Melissa 113
Wu, Brenda 114
 
Well it appears PERFECTLY sorted by Heading Asc, Person Desc. If, if if you had more than one Person with the same Heading, THEN you'll see Persons WITHIN that Heading sorted in descending order.

It seems that Heading is a SequenceID.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip,
That was just the info I needed.
Roy
 
Looking at the data, the only thing that is sorted is the # in the 3rd column. Neither the Last name or 1st name are sorted in any order.
 
Neither the Last name or 1st name are sorted in any order"...nor could they be with the sort order given.

"the # in the 3rd column". THIRD column? There were only TWO columns, Person, & Heading in the OP. Also, reading the OP's code, there are only 2 keys, meaning that only TWO columns are being sorted.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Well, for what it's worth, I tend to agree with zelgar.

Person Heading
Aditya, ROY1 2
Aibino, Cristina 3
Andrews, Mallory 4

is a mite confusing as the added number gives the impression of a third column that is sorted in ascending order. It appears as if the first column is "Person" and is also sorted ascending.

Many thanks,
D€$
 
Hmmmmmm......
Code:
......
Wilson-Gray, Sheri 38[highlight]
Zarkin, Douglas 39
Aguilar, Marlene 40[/highlight]
Henderson, Stacie 41
Hinds Banfe, Kathy 42
......

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
It would be nice to know if the data is:[pre]

Person Heading

Aditya, ROY1 2
Aibino, Cristina 3
Andrews, Mallory 4
Berlin, Ellie 5
Blum, Jackie 6
Burd, Candice 7
...[/pre]

or:
[pre]

Person Heading

Aditya, ROY1 2
Aibino, Cristina 3
Andrews, Mallory 4
Berlin, Ellie 5
Blum, Jackie 6
Burd, Candice 7
...[/pre]

or even something else.

I would vote for #1 example.

Have fun.

---- Andy
 
Well check out the post of 14 Jul 13 10:58


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top