Help with sorting more then 3 options

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
I wanted to allow my users to sort instead of 3 options, the choice to rank by 6 options.

I was creating a user form which would allow them to choose the header title from up to 6 of the 10 possible headings. It would then sort by the requested headings as soon as the user clicks on the OK button...my plan so far, so good, but putting this into practice is somewhat more tricky

Can anyone please help on this one, or direct me somewhere...please
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I assume thatyou have proper data structure with one header row and no blank rows/columns
1. turn screen updating off
2. insert blank column at start of data, add header in A1 to aid sorting
3. insert formula in A2 eg =B1&F1&I1&K1, where (in this instance), the columns that were selected were columns A and E and H and J (they are shifted by one due to added column)
4. copy formula to end of data (ie from row 2 to last row)
5. copy and paste values for column A
6. sort by coloumn A
7. delete column A
8. turn screen updating back on
 
Upvote 0
Do sequential sorts, e.g., if you want to sort by columns A-B-C-D-E-F, sort by D-E-F, then A-B-C.
 
Upvote 0
Thank you for that, I have done the following, so I can have it sorting by 6 columns, the problem is I get an error if the user doesn't choose 6 fields, is there a way around this please ?

Range("A3:Q1229").Sort Key1:=Range("T6").Value, Order1:=xlAscending, Key2:= _
Range("T7").Value, Order2:=xlAscending, Key3:=Range("T8").Value, Order3:=xlAscending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal



Range("A3:Q1229").Sort Key1:=Range("T3").Value, Order1:=xlAscending, Key2:= _
Range("T4").Value, Order2:=xlAscending, Key3:=Range("T5").Value, Order3:=xlAscending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
 
Upvote 0
Not knowing how the rest of your code works, it's hard to make a suggestion.

If they can choose 1 to 6 sort fields, then write a loop that sorts one field at a time, from least to most significant.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top