Macro to delete all rows that sum to zero

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a macro below to delete all rows there the debits and credits sum to zero


However, it also delete values that do not sum to zero


Code:
 Sub DeleteRows_SummingtoZero()
 Dim rw As Long, i As Long
 rw = Cells(Rows.Count, 1).End(xlUp).Row
 For i = rw To 2 Step -1
 If Application.Sum(Cells(i, 9)) = 0 Then
 Rows(i).Delete
 End If
 Next

 End Sub


See link below


I have also posted on Macro to delete Rows where Values add up to zero In Col H (excelforum.com)





It would be appreciated if someone could kindly assist me
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Why are you trying to use "SUM" if you are not summing anything, but only checking the value in one single column (column I)?
If you mean to check column H, it should be:
Rich (BB code):
 If Cells(i, 8) = 0 Then
 
Upvote 0
but in the file provided all valuesDebit+Creditdo not equalto 0 PER LINE.
so how this should work if there is no data to delete?
 
Upvote 0
Thanks for the reply. I am trying to dele all rows where the values in Col H total to zero up to 2 decimal places, leaving the rows where the values do not total zero . In the ample data, only the values in Grey should remain
 
Upvote 0
Thanks for the reply. I am trying to dele all rows where the values in Col H total to zero up to 2 decimal places, leaving the rows where the values do not total zero . In the ample data, only the values in Grey should remain
Did you read my reply?
It looks like your code is looking at the 9th column, which is column I, not column H.
 
Upvote 0
You can try recording a macro as:

Select the entire data range
Apply a filter
Filter column H for values of 0
Delete the visible rows under the header

If that works, review the code, then post it back if anything needs adjusting. This may help describing the problem easier as well, with resulting code to compare against.
 
Upvote 0
Thanks Jackdanice for your suggestion but there are no zero Values in Col H

where the debit and credit values add sum to zero, those rows are to be deleted
 
Upvote 0
OK, I give up.
If you are not interested in my replies, I will move on to other threads.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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