Delete Subtotal Groups that Equal 0

SAMCRO2014

Board Regular
Joined
Sep 3, 2015
Messages
160
I have search the forum and found coding on how to delete subtotal groups that equal 0 and have tried a few with no success. I must be missing something.

My subtotals are added for each change in column F and it is subtotalling amounts in Column M. I haveover 460K lines of data.I started deleted them manually but it will take forever.

DelZeroBlocks()
Dim c As Range
Dim cf As String

For Each c In Range("M2", Range("M" & Rows.Count).End(xlUp) _
.Offset(-1)).SpecialCells(xlCellTypeFormulas)
If c.Value = 0 Then
cf = c.Formula
Union(c, Range(Replace(Mid(cf, 13, Len(cf)), ")", ""))).EntireRow.Delete
End If
Next c
End Sub
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about
Code:
Sub DelZeroBlocks()
   Dim Ar As Areas
   Dim Rng As Range
   
   Set Ar = Range("M2", Range("M" & Rows.count).End(xlUp)).SpecialCells(xlConstants).Areas
   For Each Rng In Ar
      If Rng.Offset(Rng.count).Resize(1).Value = 0 Then Rng.Resize(Rng.count + 1).EntireRow.Delete
   Next Rng
End Sub
This assumes that the values in Col M are not formulae with the exception of the subtotal rows
 
Upvote 0
Are you sure that the value is 0 rather than 0.00001 or something similar?
 
Upvote 0
Looking closer you are correct. I have several amount that add up to amounts such as 1.81898940354586E-12 but the subtotal shows 0. How can I account for this?
 
Upvote 0
Try
Code:
Sub DelZeroBlocks()
   Dim Ar As Areas
   Dim Rng As Range
   
   Set Ar = Range("M2", Range("M" & Rows.count).End(xlUp)).SpecialCells(xlConstants).Areas
   For Each Rng In Ar
      If Round(Rng.Offset(Rng.count).Resize(1).Value, 0) = 0 Then Rng.Resize(Rng.count + 1).EntireRow.Delete
   Next Rng
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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