# Excel, Sorting Groups Within an Outline?



## imogul (Feb 28, 2011)

Our main program exports to excel in an outline format with each order set as it's own group. This can be a long list indeed so I was wondering if theres a way I can sort all the groups within the outline at once without having to highlight each range and sort them individually. Any insight would be awesome, thanks!


----------



## Dragoen (Apr 10, 2009)

Hi imogul,

I couldn't see your bitmap, not sure if it's a work restriction or bad file. Either way is it possible for you to post a zipped up copy of the spreadsheet(s) involved? It would make it a lot easier to see exactly what you are asking for a provide a working solution.


----------



## imogul (Feb 28, 2011)

No can do, uploading our spreadsheet would get me fired post haste. The bmp was just a screen shot. Here's an example of what I'm talking about.










In this example I would need to sort each group/section by column D. Lowest to highest.


----------



## RSpecianjr (Jan 20, 2010)

Hey,

I can't look at this today, but are the sections in groups of 8 rows? (7 days and one total without blank rows)

If it is consistant, I would loop through sorting every set of 7 rows until you get to the last used cell in column A.

Regards,

Robert


----------



## Dragoen (Apr 10, 2009)

Hi imogul,


If the first data group range is always A28, second group A1016, third group A1824, etc then this file has a macro that will sort the groups individually by the amount column when you press Ctrl-a 

If you right click on the sheet 1 tab name "sheet1" and select view code you can then expand the Modules group and open module 1. To add additional weeks to the autosorting, just copy and paste one weeks code below what is there and adjust the Range() parameters in the new block of code. There are 3 range parameters to adjust.

If you look at the code on Sheet 1, it is commented out with the ' but it will fire the sorting macro everytime the sheet is selected/activated. So you could have this sorted automatically when you open the workbook.

hope that is what you are looking for,

Roberts method will be less coding if the amount of data varies each time you fill the sheet.


----------



## imogul (Feb 28, 2011)

I wish it was consistant! Not only are the number of rows in each group varied but so are the number of groups. I was hoping there was some kind of macro that would just select the entire range in a group and then move on to the next group. Or something like that.

Also this will be in a new exported sheet each time I run the report so I'll just have to save it in my personal macro book and fire it up when I'm doing it. I'm fine with that though.


----------



## Dragoen (Apr 10, 2009)

Hi imogul,

What if you had a template sheet to import into that had a sorting macro tied to it?

So was the example you gave us just to show relative groups with 4 columns of data but the number of rows in each group could vary?

Does the data come with the summary row for each group or is that something you add?

What we need is some indicator in one of the columns that would trigger an end of group test or beginning of next group test.

Then the macro could loop through each group sorting it as it worked down the sheet through all the groups. Then you save it or copy the sheet and run a second macro to clear the input sheet for the next time you need to import new data.

Let me know...


----------



## imogul (Feb 28, 2011)

You are exactly right. 4 columns of data which a different (random) number of rows. It does export with it's own total row, in that total row columns A-C are blank and highlighted yellow. Can a blank cell serve as a trigger?


----------



## RSpecianjr (Jan 20, 2010)

Blank or Yellow, both can serve as markers. Yellow will probably be easier to use, though only slightly. Do you want the "total row" to be placed in with the macro as well? (also assume removing the yellow)


----------



## imogul (Feb 28, 2011)

I do want the total included in the macro, however since it'll have the highest number in the column anyway you can effectively ignore it. Also for simplicity sake the highlighting doesn't NEED to be removed. Whether it's there or not has no impact on my report.


----------



## RSpecianjr (Jan 20, 2010)

Hey imogul,

Will you post the workbook without data, just the yellow formatting. You can remove all the actual data and change the name of it. That will just give us something to build off of, not to mention what shade of yellow.

Thanks,

Robert


----------



## imogul (Feb 28, 2011)

Ok here you go. This is fairly typical and I would run this several times through the day. I need to sort it by column D, and print each group seperately. You can ignore the last two lines. They get left off when I print.


----------

