Using the Sort Method

J

Jill E

Hello,

I'm trying to pass the values/contents of key1 and key2 from the sort method
to separate variables. Essentially I am trying to check the sort parameters,
replace the data with an updated dataset, and then reinstate the sort. So I
tried to pass the contents of key1 and key2 to variables as show below:

With Selection.Sort
vkey1 = .key1
vkey2 = .key2
End With

Unfortunately I got an "Unable to get the Sort property of the Range class."
error.

Could someone please help!

Thanks,

Jill E
 
M

merjet

With Selection.Sort
vkey1 = .key1
vkey2 = .key2
End With

Unfortunately I got an "Unable to get the Sort property of the Range class."
error.

If you do a sort with the macro recorder on, you get something like this:

Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

Therefore, you need to change the syntax of your sort criteria.

HTH,
Merjet
 
J

Jill E

Thanks Merjet,

I am not actually trying to perform a sort, just determine the current sort
order and assign the key1 and key2 to variables. If your explanation still
applies, could you please elaborate on your explanation?

JillE
 
Top