Macro to delete rows on all sheets from sheet6 onwards where there are zeroes in Col B

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have written code to delete rows containing zeroes in Col B from sheet 6 onwards from row 2 onwards


When running the macro, it goes into a loop and after a few minutes, I need to shut it down


It would be appreciated if someone could kindly assist me



Code:
 Sub Delete_Rows_With_Zeroes()
      Dim lr As Long, I As Long, R As Long

    Application.ScreenUpdating = False
    
    For I = 6 To Worksheets.Count
        lr = Sheets(I).Cells(Rows.Count, "B").End(xlUp).Row
        For R = lr To 2 Step -1
            If Sheets(I).Range("B" & R).Value = 0 Then
                Sheets(I).Rows(R).Delete
            End If
        Next R
    Next I

    Application.ScreenUpdating = True

End Sub
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Instead of a loop, try using a helper column with a formula to identify the rows that have a zero, and delete via specialcells.
 
Upvote 0
Cross post https://www.excelforum.com/excel-pr...-rows-in-col-b-where-the-values-are-zero.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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