Autofilter with Sum

K

kaon

Hi all,

I have a macro which delete rows with a sum of zero using autofilter
but the marco deletes more than that!
I have no idea on the macro now. :(

Code:
---------------------------------
For h = 1 To arrayH.Count
For i = 1 To arrayQ.Count
ActiveSheet.Range("A1").AutoFilter Field:=cccCol
Criteria1:=arrayQ(i), Operator:=xlAnd
ActiveSheet.Range("A1").AutoFilter Field:=acctCol
Criteria1:=arrayH(h)
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1
1).SpecialCells(xlCellTypeVisible)
Set rng2
rng.Columns(17).SpecialCells(xlCellTypeVisible)
If (Not rng2 = Null) An
(Round(Application.WorksheetFunction.Sum(rng2), 0) = 0) Then
Debug.Print "Delete " & arrayQ(i) & " "
arrayH(h) & " " & _
Application.WorksheetFunction.Sum(rng2) & " "
Round(Application.WorksheetFunction.Sum(rng2), 0)
rng.EntireRow.Delete
End If
End With
Next i
Next h


Result:
---------------------------------
Delete C111 022701 0 0
Delete C286 022701 -179737.193541667 -179737
Delete C302 022701 0 0
Delete C320 022701 268691 268691
Delete C370 022701 -445900 -445900
Delete C600 022701 119197.992268519 119198
Delete C614 022701 1216707.43701389 1216707
Delete C617 022701 0 0
Delete C939 022701 2.1600499167107E-12 0
Delete CB12 022701 0 0
Delete C505 023101 41669.32 41669
Delete C600 023101 80557.6 80558
Delete CB12 023101 0 0
Delete CH09 023101 0 0
Delete CH40 023101 1200 1200
Delete CM77 023101 11158 1115
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top