Delete Rows with 0 Values

Ed_B

New Member
Joined
Mar 28, 2018
Messages
19
Office Version
  1. 2019
Platform
  1. Windows
Thank you in advance for your help.

I have a list of items some of which have 0 values. They are separated in groups and I would like to output the list keeping the groups, but deleting the rows with 0 values and adding a grand total:

[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 256"]
<tbody>[TR]
[TD="colspan: 4, align: center"]INPUT[/TD]
[/TR]
[TR]
[TD]Item[/TD]
[TD]Unit Price[/TD]
[TD]Quantity[/TD]
[TD]Total Price[/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]Fruits[/TD]
[/TR]
[TR]
[TD="align: center"]Peaches[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD]Mangos[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD]Berries[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]Vegetables[/TD]
[/TR]
[TR]
[TD]Carrots[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD]Peas[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]8[/TD]
[/TR]
[TR]
[TD]Potato[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]OUTPUT[/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]Fruits[/TD]
[/TR]
[TR]
[TD="align: center"]Peaches[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD]Berries[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]Vegetables[/TD]
[/TR]
[TR]
[TD]Peas[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]8[/TD]
[/TR]
[TR]
[TD]Potato[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="colspan: 4, align: center"]Total[/TD]
[/TR]
[TR]
[TD="colspan: 2"]Total Price[/TD]
[TD="align: center"][/TD]
[TD="align: center"]21[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Thanks again

Ed
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Assuming your Total row is in column D

Code:
Sub DeleteRow()


Dim RowToTest As Long


For RowToTest = Cells(Rows.Count, 4).End(xlUp).Row To 2 Step -1


With Cells(RowToTest, 4)
    If .Value <> 0 Then 
    Rows(RowToTest).EntireRow.Delete
End With


Next RowToTest


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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