View Full Version : Need help with program deleting rows
patrider
08-26-2016, 12:59 AM
1694416945
Hey guys,
I wanna remove every row where the sum of those 3 numbers equals Zero
i dont know any further how it may work, guess i Need to kinda check for decimals aswell.
Thanks in advance!
Always delete Rows from the bottom up and Columns from right to left.
Sub VBAX_SamT()
Dim Rw As Long
'From the bottom row on the sheet, Column B, Press Ctrl+UpArrow. Get the Row number. Count backwards by 1
For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1
'Use only one of the below IFs
If Sum(Range("B" & Rw & ":D" & Rw) = 0 Then
If Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then
If Sum(Cells(Rw, "B").Resize(1, 3)) = 0 Then
Rows(Rw).Delete
End If
Next Rw
End Sub
patrider
08-29-2016, 04:11 AM
Always delete Rows from the bottom up and Columns from right to left.
Sub VBAX_SamT()
Dim Rw As Long
'From the bottom row on the sheet, Column B, Press Ctrl+UpArrow. Get the Row number. Count backwards by 1
For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1
'Use only one of the below IFs
If Sum(Range("B" & Rw & ":D" & Rw) = 0 Then
If Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then
If Sum(Cells(Rw, "B").Resize(1, 3)) = 0 Then
Rows(Rw).Delete
End If
Next Rw
End Sub
Hey,
thanks for the help, but i m getting a syntaxerror for this line: For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1
and i kinda can't figure out whats wrong.
p45cal
08-29-2016, 06:26 AM
remove the dot after Count
And use only one of the three Ifs
patrider
08-30-2016, 02:27 AM
remove the dot after Count
And use only one of the three Ifs
Thanks for the super fast replies!
I changed a few minor things so it works for me now, it looks like this:
Sub VBAX_SamT()
Dim Rw As Long
For Rw = (Cells(Rows.Count, "B").End(xlUp).Row) To 3 Step -1
If Application.WorksheetFunction.Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then
Rows(Rw).Delete
End If
Next Rw
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.