I can get the information from the user. What I do not know is, how do I code the part of the instruction using a variable that I can set to either xlascending or xldescending.
Order1:=[order that the user selected]
Main Topics
Browse All TopicsI need to get this part of the sort from the user. I need to test thier response and set accordingly.
Order1:=xlDescending or Order1:=xlAscending
How can I change this programatically?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
...it depends on how you have the order selection (from the user) stored (as a Boolean value, as a String, or so on).
If blnOption_Is_Ascending is defined as a Boolean data type, and holds True for Ascending (or False for Descending), or strOrder_Selected contains an "A" for Ascending (or any other value for Descending)...
1) Duplicate your sort statement but change the Order1 value accordingly...
If (blnOption_Is_Ascending) Then
<sort statement> Order1:=xlAscending
Else
<same sort statement as above but...> Order1:=xlDescending
End If
2) As I mentioned above...
<sort statement> Order1:=IIf(strOrder_Selec
or
<sort statement> Order1:=IIf(blnOrder_Is_As
BFN,
fp.
Hello wshepard
Maybe you are intimidated by the names xlAscending and xlDescending. They are just constants to make the code more readable, and have the values 1 and 2, respectively. You can verify this in the immediate pane:
? xlDescending
To sort descending, use any method to generate the value 2, e.g.:
Order1:=2
Order1:=20/10
Order1:=intSelectedSort
That would me my choice, store the user's answer in a variable, and pass that variable to the sort method...
Cheers!
(°v°)
Many Excel parameters are defined using pre-defined types which, if known, can aid with using variables to store parameter values. In this case the type is XlSortOrder which can be used to define a variable:
Dim MySortOrder As XlSortOrder
If you type the variable MySortOrder followed by an equal sign you will see a Quick Info popup listing the possible values.
These statements produce the same results:
MyRange.Sort [A1], Order1:=xlAscending
MyRange.Sort [A1], Order1:=1
Dim MySortOrder As XlSortOrder
MySortOrder = xlAscending
MyRange.Sort [A1], Order1:=MySortOrder
Thinking outside the box, how about putting two different sort buttons on the worksheet itself? One button for sorting ascending and one for descending. This way you don't to ask the user nor do you have to interpret a response. I posted an example using iconic buttons here:
http://www.zorvek.com/down
Kevin
Business Accounts
Answer for Membership
by: fanpagesPosted on 2006-05-26 at 14:59:02ID: 16772774
How about this...
Order1:=IIf(MsgBox("[Yes] for Ascending, [No] for Descending", vbQuestion Or vbYesNo, "Select Sort Order") = vbYes, xlAscending, xlDescending)
BFN,
fp.