Delete Rows where Col B & C have zeroes

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,566
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to delete rows containing zeroes in Col B & C, but only the first row containing zeroes are deleted



Book1
BCD
2008
30032.536
4KR-3414-389.984-2599.9
5KR-3414389.98442599.896
6KR-3424-714.783-4765.22
7KR-3424714.78284765.217
8KR-2510-714.783-4765.22
9KR-2510714.78284765.217
10KR-3424-714.783-4765.22
11KR-3424714.78284765.217
120010
13KR-22101.252492.4368
14KR-735069.9504466.336
Sheet1



See my code below

Code:
 Sub Delete_Zero_Values()
    Dim lr As Long, cell As Range
    With Sheets(1)
    .Application.ScreenUpdating = False
        lr = .Cells(.Rows.Count, "A").End(xlUp).Row
        For Each cell In .Range("B2:C" & lr)
            If cell = 0 Then cell.EntireRow.Delete
        Next cell
        .Application.ScreenUpdating = True
    End With
  
End Sub

It would be appreciated if someone could assist me
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
If both col B & C have to be 0 try
Code:
Sub Delete_Zero_Values()
   Dim lr As Long, i As Long
   With Sheets(1)
      Application.ScreenUpdating = False
      lr = .Cells(.Rows.Count, "A").End(xlUp).Row
      For i = lr To 2 Step -1
         If Cells(i, 2) = 0 [COLOR=#ff0000]And[/COLOR] Cells(i, 3) = 0 Then
            Rows(i).Delete
         End If
      Next i
      Application.ScreenUpdating = True
   End With
End Sub
If either of can be 0 then change the And to Or
 
Upvote 0
Here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub Delete_Zero_Values()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  Range("B1:B" & LastRow).Value = Evaluate("IF(B1:B" & LastRow & "&C1:C" & LastRow & "=""00"",""#N/A"",B1:B" & LastRow & ")")
  Columns("B").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thanks for the help guys, much appreciated
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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