VBA inserting subtotal(s) rows

kweaver

Well-known Member
Joined
May 12, 2009
Messages
2,940
Office Version
  1. 365
Before I totally kill my day trying to do this, I thought I'd post this considering how quickly perfect solutions are created.

I have a sheet which is already sorted by column H (starting in row 5).
[thanks, Fluff]

I now need to put in a subtotal row for each group of names in H5:Hn and total columns I, J, K.

So, if H5 on has

John
John
John
Mary
Mary
Mary
Mary
Kevin
Kevin

I need subtotals for I, J, and K for each of those folks below each of their names

John
John
John
--- John's subtotals for I, J, and K

Etc.

I believe I have to work from the bottom up, but am not sure how to create the breaks and then insert the totals for each person.

Thanks in advance.
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Well, I did a macro recording and it created the subtotals as I needed. But, another issue came up.

While the subtotals appeared as needed, I then called another macro that was to put borders around the data.
But, when that was called, all of the subtotals vanished!

This is the subtotal macro that was recorded:

Code:
Sub SubTot()
'
' SubTot Macro
'

'
    Dim lr As Long
    lr = Sheets("Reformatted").Cells(Rows.Count, "A").End(xlUp).Row
    Range("A4:L" & lr).Select
    Selection.Subtotal GroupBy:=8, Function:=xlSum, TotalList:=Array(9, 10, 11) _
        , Replace:=True, PageBreaks:=False, SummaryBelowData:=True
End Sub

Edit: it seems if I run SubTot and then Borders on their own rather than being called by the master macro routine, it's fine.
 
Last edited:
Upvote 0
I thought the problem was resolved when I made sure I didn't have anything interrupting the macros. But, when I copied the sheet with the subtotals to a new workbook to save it, the subtotals vanished.

In the original workbook where the subtotals are being calculated, they've managed to vanish again!
 
Last edited:
Upvote 0
I think I'm learning...I think it was a problem because I needed the sheet to be active.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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