Subtotal Function vba

Ralter649

New Member
Joined
Oct 20, 2017
Messages
36
I am subtotaling orders for total pieces and weight.
Example:

ITEM.....PCS......WT............IN STOCK
Shirt......5...........7.................96
Shirt......12.........16...............96
Shirt......3...........5..................96
------------------------
Shirt....20..........28...........?(96)?

MY CODE:

With ws
'find last data row
endrow = Cells(Rows.Count, stcol).End(xlUp).Row


'sort data
Set drng = .Range(.Cells(strow, stcol), .Cells(endrow, endcol))
drng.Sort Key1:=.Cells(strow + 1, stcol), Order1:=xlAscending, Header:=xlYes


'apply Excel SubTotal function
.Cells.RemoveSubtotal
drng.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(6, 9)

End With



The 'GroupBy:=1' is what makes the Shirt in the total line and if i change the 1 to a 4 it will put the 96 in the total line. How do i get it to show 1 and 4 (Shirt and 96) at the same time?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you include the "In Stock" column in the 'drng' variable, then it will subtotal that column. You can exclude that column to get the subtotals of the pieces and weight, then add a line to bring the "In Stock" quantity down to the row with the subtotals.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top