subtotals and sorts

G

Guest

Hi and thanks for the help. I am using Excel 2003. I have a spreadsheet with
about 200 rows and 5 columns of data. There are numerous rows that hold
subtotals.

I need to sort based on the subtotals--BUT keep all the rows together that
belong with that subtotal. Is that possible??
 
G

Guest

I can be done with a custom macro. The macro would need find the continuous
rows associated with each subtotal. The swap the two groups. It would be a
bubble sort routine which swaps multiple rows of data. the general form of a
buble sort is

for i = 1 to (lastrow - 1)
For j = (i + 1) to lastrow

if (subtotal_blocki > subtotal_blockj) then

temp_block = blocki
blocki = blockj
blockj =temp_block

end if
next j
next i

the block sizes may not be the same number of rows, do instead of swapping
some combination of .copy, .insert.entirerow, and .delete.entirerow would be
used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top