Excel 2013 VBA, Delete Entire Row If SUM Is 0

Hello,

How would I loop through each row and delete the entire row if the sum of the cell in column C, F, and G is equal to 0.

For example, there are names in Range A1:A100. If C1, F1, and G1 values sum to 0, delete the entire row 1. Repeat until A100.

The loop range needs to be variable, as Column A may only have 7 values or may 700 values.

Thank you in advance for your help.
EnigmaMatterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hakan YılmazTechnical Office MEP EngineerCommented:
This works on active worksheet.
Sub deletezerorow()
    Dim iterrowno As Integer
    For iterrowno = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
        With ActiveSheet
            If .Cells(iterrowno, 3) + .Cells(iterrowno, 6) + .Cells(iterrowno, 7) = 0 Then .Rows(iterrowno).Delete
        End With
    Next iterrowno
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EnigmaMatterAuthor Commented:
I get a Type Mismatch Error w/

Dim iterrowno As Integer
For iterrowno = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
        With ActiveSheet
            If .Cells(iterrowno, 3) + .Cells(iterrowno, 5) + .Cells(iterrowno, 7) + .Cells(iterrowno, 9) + .Cells(iterrowno, 11) + .Cells(iterrowno, 13) = 0 Then .Rows(iterrowno).Delete
        End With
    Next iterrowno

Open in new window


Is it because I have blanks in some of those columns?

Also, I have header information in Row 1 through 5 (some blank rows in there too). Can I make it start on Row 6
0
EnigmaMatterAuthor Commented:
Hello,

I changed the Count To 1 to Count to 6 to skip the header rows and your solution works perfectly!

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.