Subtotal values and then hide rows

Extivalis

New Member
Joined
Mar 21, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I was wondering if there's a way to right a macro into VBA for this:

If I have a large list of data (range will vary), that's already sorted by text in Column H, I want to take all the values in Column F for the rows where Column H's value is the same, sum/subtotal those into Column G of the last row that Column H matches, and then hide there rows where G is blank.
(attached photos showing example of what I'm trying to go From and To - any identifying info removed)
 

Attachments

  • From this.JPG
    From this.JPG
    169.5 KB · Views: 16
  • To this.JPG
    To this.JPG
    52.7 KB · Views: 14

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think all you need is this.

VBA Code:
Sub Sum_Groups()
  With Range("G2:G" & Range("F" & Rows.Count).End(xlUp).Row)
    .Formula = "=if(H2=H3,"""",SUM(F$2:F2)-SUM(G$1:G1))"
    .Value = .Value
    .SpecialCells(xlBlanks).EntireRow.Hidden = True
  End With
End Sub
 
Upvote 0
Solution

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