I have a report where i need to remove the rows with no data in the cells or a zero within a range column C to O.
This code i have almost does it perfectly, but i found a fatal flaw in the logic. If the row has a positive and negative value that sum to zero it will be deleted while i would still need to retain that row.
I really appreciate the assistance from this site as I have been able to really automate many of my reports and help people in other departments! you guys rock! Thank You!
Dim rw As Long, i As Long
rw = Cells(Rows.Count, 1).End(xlUp).Row
For i = rw To 6 Step -1
If Application.Sum(Cells(i, 3).Resize(1, 17)) = 0 Then
Rows(i).Delete
End If
Next
Rather than checking the SUM, loop through each cell and check if its valid.
To explain this better I will use pseudo code for you:
Pseudo-Code made into rough code
Dim rw As Long, i As Long
Dim rng As Range
Dim validRow As Boolean
validRow = false
rw = Cells(Rows.Count, 1).End(xlUp).Row
For i = rw To 6 Step -1
Set rng = (Cells(i, 3).Resize(1, 17))
For Each cell In rng
If Not IsEmpty(cell) Then
If cell.value <> 0 Then
validRow = true
End If
End If
If validRow = true Then
Exit For
End If
Next cell
If validRow = false Then
Rows(i).Delete
End If
validRow = false
Next
[@LL edit: changed >0 to <>0 too look for anything different than zero, to account for rows populated with only negative values]