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: 11
  • To this.JPG
    To this.JPG
    52.7 KB · Views: 8

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Have you tried using a pivot table?
 
Upvote 0
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

Forum statistics

Threads
1,215,214
Messages
6,123,660
Members
449,114
Latest member
aides

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