Jordan,
Try something like this
Sub Sortit(rngToSort As Range, _
rng1 As Range, Optional rng2, Optional rng3)
If IsMissing(rng2) Then Set rng2 = rng1
If IsMissing(rng2) Then Set rng3 = rng2
rngToSort.Sort key1:=rng1, _
key2:=rng2, _
key3:=rng3
End Sub
rngTosort is the whole range to be sorted, and pass the keys as rng1,2,3
omitting if required.
It will sort key2 twice or even key1 three times, but that shouldn't be a
problem.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"jordanctc " wrote in message
...
Good morning.
In Excel 2003, I know you can have three criteria of sorting (Sort by,
Then by, Then by).
I am trying to create a form where I give the user the same 6 options
(representing columns D through I of the sheet) for sorting. I have
form controls to stop sorting the same column more than once but I'm
just not sure what the VBA should be for the sort.
Can I use variables and pass them to a single sort statement?
Do I need different sort statements if they want to sort by 1, 2, or 3
criteria?
Thanks,
Jordan
---
Message posted from http://www.ExcelForum.com/