ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
Hi. I have here a macro for making subtotals for a set of data. However when I run the code, it does not give the proper subtotals.
See below the result when I run the code:
⬇
I also attached the code for reference:
See below the result when I run the code:
⬇
I also attached the code for reference:
VBA Code:
Sub SubtotalMacro()
'
Dim Lastrow As Long
Sheets(1).Activate
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:D" & Lastrow).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3, 4), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3, 4), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True
End Sub