Deleting the entire row if the numbers add up to 0 in Excel using VBA

Young_Money

New Member
Joined
Jul 8, 2011
Messages
23
Hello.
I am trying to create a Sub that will delete the entire row in Excel with VBA if the number adds up to zero.

For example
0 0 0 0 0
1 3 0 1 3
0 2 0 1 4
2 0 0 2 5

I can use the SUM function to add it all up so I would get
0
8
7
9

Then, the entire first row would be deleted because the SUM = 0.

However, I have no clue how to do this.
Would anybody be able to give me any pointers or help me out with this?

Thanks.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Give that a shot

Code:
dim x as integer
x = 0
with range("a1")
   do while not IsEMpty(.offset(x,0))
      if not Application.Worksheetfunction.Sum(.offset(x,0).entirerow)) then 
        .offset(x,0).entirerow.delete
        'missing a row now, need to decrement x
        x=x-1
      end if
 
   x=x+1
   loop
end with
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

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