LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Dynamically set Sort keys

Hello All,

I'm trying to create a worksheet that has a database with the capability to
dynamically set each of the three sort keys. My database is in the range
from a5:g15, the field names are in row 5. I've created in cell drop down
lists using validation in cells a4, b4, c4. I'd like to use these dropdowns
to select sort keys 1-3 respectively.

Searching google I've found some posts that have something similar with a
single sort key that was posted by Steve Bell:

Dim x as Integer

x = Worksheetfunction.Match(Range("A3"),Range("A5:g15" ), 0)

Selection.Sort Key1:=Columns(x), Order1:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

but I can't figure out how to modify it to accomodate three sort keys. I've
tried dimensioning two other variables y and z for the other sort keys and
the pasting the above code with x changed to y and z respectively....no
luck, I keep getting errors.

This is what I have so far.

Dim x as Integer
Dim y as Integer
Dim z as Integer

x = Worksheetfunction.Match(Range("A3"),Range("A5:g15" ), 0)
y = Worksheetfunction.Match(Range("b3"),Range("A5:g15" ), 0)
z = Worksheetfunction.Match(Range("c3"),Range("A5:g15" ), 0)

Selection.Sort Key1:=Columns(x), Order1:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Selection.Sort Key2:=Columns(y), Order1:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Selection.Sort Key3:=Columns(z), Order1:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Could anyone possibly help me figure out the proper syntax?...

Thanks for your help in advance.

Will


 
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
Sort worksheet on multiple keys - Primary, secondary, tirterary, etc. Doug Mc New Users to Excel 12 October 22nd 09 02:18 AM
Many Sort Keys [email protected] New Users to Excel 13 August 3rd 07 01:08 AM
Getting handle to Row # dynamically prakash Excel Discussion (Misc queries) 1 September 12th 06 08:53 AM
Dynamically set a range? BKGT Excel Worksheet Functions 3 April 27th 06 03:26 PM
VBA Sort method w/more than 3 Keys KenRoy Excel Discussion (Misc queries) 1 August 26th 05 10:48 PM


All times are GMT +1. The time now is 10:04 PM.

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

About Us

"It's about Microsoft Excel"