xldescending and xlascending

blue333

Board Regular
Joined
Mar 19, 2009
Messages
64
Hey

I am creating a macro which sorts three columns of my choosing in either ascending or descending order. I would like to be able to specify the order (ascending or descending) from a drop down list. I have done this part with named ranges which store the choices. However, the macro for some reason does not pick up the values. Sheet1.Range("primary_key_order").Value is producing the value it should (xldescending or xlascending) because i created a msgbox to see the value. The code will work if i use the default values. I am using Excel 2007 and Vista. Below is my code:

'DOES NOT WORK
Sheet3.Sort.SortFields.Add Key:=Range(PrimaryKeyRange), SortOn:=xlSortOnValues, Order:=Sheet1.Range("primary_key_order").Value, DataOption:=xlSortNormal

'WORKS
Sheet3.Sort.SortFields.Add Key:=Range(PrimaryKeyRange), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal

'REST OF CODE...

A workaround is to use multiple if statements or case statements but these approaches get a bit messy.


Any suggestions for why my approach doesn't work?

Thanks!!
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
What exactly is in your range primary_sort_order? Is it a 1 or a 2 or is it "xlAscending" or "xlDescending"?

I ask because xlAscending is a constant with a value of 1.
 
Upvote 0
What exactly is in your range primary_sort_order? Is it a 1 or a 2 or is it "xlAscending" or "xlDescending"?

I ask because xlAscending is a constant with a value of 1.

it is actually "xlAscending" or "xlDescending" strings. so if xlAscending is 1 then what is xlDescending?
 
Upvote 0
Go to the VBE, hit the F2 key. Type "xldescending" into the search box. Click on the contant in the members pane. Look at the bottom of the object browser. There will be a pane with the value. And that's how you suss out contants' values. :wink:
 
Upvote 0
thanks for teaching a man how to fish and not giving the fish...much appreciated!! now i know!!!!!!
 
Upvote 0
thanks for teaching a man how to fish and not giving the fish...much appreciated!! now i know!!!!!!
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,411
Members
448,894
Latest member
spenstar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top