I have created a spreadsheet using VB, populated it with a few thousand rows and subtotaled it using the Range().Subtotal method.

So far so good!

I now need to sort the rows by the subtotal value in the subtotal column. I know it's possible because I can do this 'manually' on the spreadsheet simply by clicking on the column head and hey-presto the groups are sorted, not the individual rows.

I have tried the following code:

Range(groupStartCell).Sort(Key1:=worksheet.Range("F2" & lastRow.ToString), Order1:=Interop.Excel.XlSortOrder.xlDescending, Orientation:=Interop.Excel.XlSortOrientation.xlSortRows, Header:=Interop.Excel.XlYesNoGuess.xlGuess, OrderCustom:=1, MatchCase:=False)

and it does nothing!