Hi,
I use shift-end-down, then shift-end-right to select all data in my spreadsheet.
I then click Data, Subtotals, and select At each change in column = B, Use Function = Sum, Add Subtotal to = Column R and click ok.
Then I do the same for column D.
Works fine - I get subtotals for both column D and Column B for all the rows in the spreadsheet.
I record this in VBA and this is the code:
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Subtotal GroupBy:=2, Function:=xlCount, TotalList:=Array(18), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Selection.Subtotal GroupBy:=4, Function:=xlCount, TotalList:=Array(18), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True
When the recorded macro is run, the last row is not included in the column D subtotal count. It is left by itself without a subtotal.
I have done this over and over and over and get the same result.
Can anyone see why subtotals functions properly when "live" on the worksheet, but leaves one line out when used in a macro?
Bookmarks