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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.