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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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