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

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,570
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

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