Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Code for variable sort order

Put this declaration on top and try changing the sort orders 1 for ascending
and 2 for descending.

Dim mSortOrder1 As Variant,mSortOrder2 As Variant,mSortOrder3 As Variant

mSortOrder1 = 1
mSortOrder2 = 1
mSortOrder3 = 1


--
Jacob (MVP - Excel)


"BB Ivan" wrote:

I'm trying to code a program that allows flexible sorting based on certain
criteria. I'm having trouble using a variable for sort order. Here is the
code. When I hard code sort order (i.e., xlAscending or xlDescending) it
works fine. Any suggestions on how to make sort order accept a variable?

Selection.Sort Key1:=Range(mSortKey1), Order1:=mSortOrder1, _
Key2:=Range(mSortKey2), Order2:=mSortOrder2, _
Key3:=Range(mSortKey3), Order3:=mSortOrder3, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

Thanks,

Ivan

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Code for variable sort order

That works! (xlAscending/Descending did not). Thanks!

Do you know the whereaboubts of a reference for all "xl" settings like
these? For example, I've encountered the same problem trying to establish
variables for print header/footer settings.

"Jacob Skaria" wrote:

Put this declaration on top and try changing the sort orders 1 for ascending
and 2 for descending.

Dim mSortOrder1 As Variant,mSortOrder2 As Variant,mSortOrder3 As Variant

mSortOrder1 = 1
mSortOrder2 = 1
mSortOrder3 = 1


--
Jacob (MVP - Excel)


"BB Ivan" wrote:

I'm trying to code a program that allows flexible sorting based on certain
criteria. I'm having trouble using a variable for sort order. Here is the
code. When I hard code sort order (i.e., xlAscending or xlDescending) it
works fine. Any suggestions on how to make sort order accept a variable?

Selection.Sort Key1:=Range(mSortKey1), Order1:=mSortOrder1, _
Key2:=Range(mSortKey2), Order2:=mSortOrder2, _
Key3:=Range(mSortKey3), Order3:=mSortOrder3, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

Thanks,

Ivan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can i link a variable cost code with a variable sum I need help!! Excel Discussion (Misc queries) 0 August 1st 08 11:40 AM
Retaining Sort order in the Sort Dialog box CBittinger Excel Discussion (Misc queries) 2 January 9th 08 05:01 PM
Sort sheet based on particuilar sort order Also Excel Worksheet Functions 4 January 3rd 08 09:31 AM
Sort : how can I use a variable in a VB sort function? El Bee Excel Worksheet Functions 3 February 16th 06 09:34 PM
variable code?? Paul Excel Discussion (Misc queries) 1 April 5th 05 06:37 PM


All times are GMT +1. The time now is 07:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"