Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Anyone come up with an efficient way of sorting data based on variable number of sort fields at runtime? For example, if end-user wants to sort data on column 1, code is straighttforward: myRange.Sort key1:=.Cells(1,1) However, if end-user can sort on upto 2 columns, say column x, and y, code gets clunky: if (user specified column x only) then myRange.Sort key1:=.Cells(1,x) else if (user specified column x and y) then myRange.Sort key1:=Cells(1,x), key2:=Cells(1,y) Now if end-user can sort on upto 3 columns, say x, y, z the code gets even more clunky. if (user specified column x only) then myRange.Sort key1:=.Cells(1,x) else if (user specified column x and y) then myRange.Sort key1:=Cells(1,x), key2:=Cells(1,y) else if (user specified columnx and y and z) then myRange.Sort key1:=Cells(1,x), key2:=Cells(1,y), key3=Cells(1,z) Is there a better solution? Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding more sort fields to the SORT Dialog Box | Excel Discussion (Misc queries) | |||
number of fields in the row fields in pivot table | Excel Discussion (Misc queries) | |||
SUM of a variable range of fields | Excel Worksheet Functions | |||
Need pie chart with number of fields instead of info in fields | Charts and Charting in Excel | |||
Sorting by more than 3 Fields in VBA | Excel Programming |