Group and sticky subgroup sorting excel VBA

jjsauer

Board Regular
Joined
Jan 11, 2012
Messages
58
Hello,
I was curious if anybody could point me in the right direction.
Lets say I have 5 categories and each category has 5 subcategories. How could I set up a macro to not only sort the 5 subcategories (descending), but sort the 5 main categories (descending) AND keep the newly sorted subcategory list underneath it?
For example(left is data, right is what I want after the sorting):




Category 1 100 Category 3 500
Subcat 1 1 Subcat 11 5
Subcat 2 2 Subcat 14 4
Subcat 3 3 Subcat 12 3
Subcat 4 4 Subcat 15 2
Subcat 5 5 Subcat 13 1
Category 2 300 Category 5 400
Subcat 6 1 Subcat 21 5
Subcat 7 3 Subcat 24 4
Subcat 8 5 Subcat 23 3
Subcat 9 2 Subcat 22 2
Subcat 10 4 Subcat 25 1
Category 3 500 Category 2 300
Subcat 11 5 Subcat 8 5
Subcat 12 3 Subcat 10 4
Subcat 13 1 Subcat 7 3
Subcat 14 4 Subcat 9 2
Subcat 15 2 Subcat 6 1
Category 4 200 Category 4 200
Subcat 16 1 Subcat 17 5
Subcat 17 5 Subcat 20 4
Subcat 18 3 Subcat 18 3
Subcat 19 2 Subcat 19 2
Subcat 20 4 Subcat 16 1
Category 5 400 Category 1 100
Subcat 21 5 Subcat 5 5
Subcat 22 2 Subcat 4 4
Subcat 23 3 Subcat 3 3
Subcat 24 4 Subcat 2 2
Subcat 25 1 Subcat 1 1


Thanks in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
crap...the spacing didn't stay, I hope you can still understand. Let me know if I should repost it.
 
Upvote 0
Put the major and minor categories in separate columns, duplicating the major category as necessary.
 
Last edited:
Upvote 0
@ SHG, I don't think that would work. Unless I misunderstood, it basically just sorted everything as though it was in one column. I appreciate it, but it appears I cannot automate everything. I could try a longer, messier macro with multiple sheets, but that just isn't very pretty.
 
Upvote 0

Forum statistics

Threads
1,216,209
Messages
6,129,517
Members
449,515
Latest member
lukaderanged

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