Macro to delete row if two columns contain zero amount

dnlrsms

New Member
Joined
Apr 16, 2013
Messages
8
Hi,
I need help getting a macro to delete the entire row if column A is zero and column B is zero, but it should not delete the row if column B contains an amount greater than 0.

I have done some searching, but I was not able to find an example that can do this.
Column A = 0, Column B = 0 - Delete the row
Column A = 0, Column B = 1 - Do not delete the row
Column A = 1, Column B = 0 - Do not delete the row
Column A = 1, Column B = 1 - Do not delete the row

Any help will be greatly appreciated.

Regards
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try

Code:
Sub TEST()
Dim LR As Long, I As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For I = LR To 1 Step -1
    With Range("A" & I)
        If .Value = 0 And .Offset(, 1).Value = 0 Then .entirerow.Delete
    End With
Next I
End Sub
 
Upvote 0
This should work.

Code:
Sub DeleteRows()
Dim rng As Range, cel As Range
Dim N As Long
Set rng = ActiveSheet.Range("A1:A" & ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row)
For N = rng.Rows.Count To 1 Step -1
If rng.Cells(N, 1) = 0 And rng.Cells(N, 2) = 0 Then
    
    rng.Cells(N, 1).EntireRow.Delete shift:=xlShiftUp
End If
Next N
 
 

End Sub
 
Upvote 0
This should work.

Code:
Sub DeleteRows()
Dim rng As Range, cel As Range
Dim N As Long
Set rng = ActiveSheet.Range("A1:A" & ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row)
For N = rng.Rows.Count To 1 Step -1
If rng.Cells(N, 1) = 0 And rng.Cells(N, 2) = 0 Then
    
    rng.Cells(N, 1).EntireRow.Delete shift:=xlShiftUp
End If
Next N
 
 

End Sub

Hi nuked,

Thank you so much for the code. It is awesome and is just what I needed to complete my project.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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