I am using vba to sort and then apply subtotals (along with sytles and formats for the subtotal rows). I have come across a bug in excel that appears to mean I have to start again without the subtotal method. (I have the impression that the precise bug seems to differ between excel versions though I have not tested this aspect extensively.)
This is going to be part of a spreadsheet used by top management. They are going to insert new records (through press of a button), change existing data (with data validation), sort and refresh the sub-totals by press of a button. They have Excel 2003 sp2 or Excel 2000. I am testing on Excel 2003 SP3.
The problem can be seen by putting this simplified data into your spreadsheet:
Field1 Field2 Amount
North banana 10
North banana 11
North apple 15
South apple 15
South apple 17
South apple 10
South [red]apple[/red] 11
East banana 15
East banana 15
East apple 11
East apple 15
East apple 15
And applying this code (or using sub-totals manually).
Select any cell within the data within the data then run the macro.
Change the red cell to banana and run the macro again. Works much better if the data is like this.
I am surprised not to find loads of stuff about this on the web. I thought I would find plenty of references and solutions.
So, unless you know better then I need to rapidly find or develop code to replicate the subtotal wizard without the bugs. Any ideas, hints etc?
Gavin
This is going to be part of a spreadsheet used by top management. They are going to insert new records (through press of a button), change existing data (with data validation), sort and refresh the sub-totals by press of a button. They have Excel 2003 sp2 or Excel 2000. I am testing on Excel 2003 SP3.
The problem can be seen by putting this simplified data into your spreadsheet:
Field1 Field2 Amount
North banana 10
North banana 11
North apple 15
South apple 15
South apple 17
South apple 10
South [red]apple[/red] 11
East banana 15
East banana 15
East apple 11
East apple 15
East apple 15
And applying this code (or using sub-totals manually).
Code:
Sub TestSubtot()
With Selection
.CurrentRegion.Select
.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
.CurrentRegion.Select
.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True
End Sub
Change the red cell to banana and run the macro again. Works much better if the data is like this.
I am surprised not to find loads of stuff about this on the web. I thought I would find plenty of references and solutions.
So, unless you know better then I need to rapidly find or develop code to replicate the subtotal wizard without the bugs. Any ideas, hints etc?
Gavin