Macro to Delete values summing to zero where A/c is the same

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,568
Office Version
  1. 2021
Platform
  1. Windows
I have values in Col D and a/c numbers in Col A

Where the values sum to zero for the same account number for e.g if the a/c 1 is 1 , and the values for 1 sum to zero then all the rows for 1 to be deleted etc

I have highlighted those rose that need to be deleted

It would be appreciated if someone can provide me with code to do so


Se link below

 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try:
VBA Code:
Sub MyDeleteMacro()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant, rng As Range, total As Long
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
    Set rng = Range("D2", Range("D" & Rows.Count).End(xlUp))
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With Range("A1")
                    .CurrentRegion.AutoFilter 1, v(i, 1)
                    total = Application.WorksheetFunction.Sum(rng.SpecialCells(xlCellTypeVisible))
                    If total = 0 Then
                        ActiveSheet.AutoFilter.Range.Offset(1).EntireRow.Delete
                    End If
                End With
            End If
        Next i
    End With
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,660
Messages
6,126,089
Members
449,288
Latest member
DjentChicken

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