Forgive me for my lack of experience with VBA. I am trying to do the best I can with google and common sense. So I've created a macro that ends up subtotaling data, going to the second level of subtotals, and then deletes all rows with an amount balance of 0. However my problem is that my current macro looks at all data and deletes the row if the amount balance of 0. I want the macro to go into subtotal level 2 and delete all rows with 0. That way only lines with a amount balance subtotal of 0 will get deleted and not just any line that has an amount balance of 0. This is the code of my current macro.
Range("A5").Select
Selection.Subtotal GroupBy:=23, Function:=xlSum, TotalList:=Array(56), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim lastrow As Long, r As Long
lastrow = ActiveSheet.UsedRange.Rows.Count
For r = lastrow To 1 Step -1
If UCase(Cells(r, 56).Value) = "0" Then Rows(r).Delete
Next r
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
I either need it to go to level 2, filter amount balance to only show amount balance subtotals of 0 and then delete any rows that are on the screen or go to level 2 and delete any rows with an amount balance of 0. One of the problems I've also run into is that the data doesn't start until row 5. Row 4 is column headers. Also when looking at level 2 of subtotals the first line of data is not row 5 but row 8 for example because that is where the first subtotal is located. The amount balance column is column 56 by the way. Any ideas?
Btw here is an example of what i'm talking about:
Level 2:
A Total 0
B Total 20
C Total 30
Level 3(expanded level 2):
A 0
A 0
A Total 0
B 20
B 0
B Total 20
C 10
C 20
C 0
C Total 30
I would want it to delete both rows of A and no other rows. Even though one row of B and C have an amount balance of 0, their subtotal is not 0 so I do not want to delete any of their rows. Thus I would want the macro to simply look at level 2 and delete the row A Total.