Macro to delete rows containing zeroes

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro that works perfectly if I run the macro from sheet3, but if I run it from a sheet called macro, I does not delete the rows containing zeroes where Col B & C are zeo

Please check & advise


Code:
 Sub Delete_Zero_Values()

   Dim LR As Long, i As Long
   With Sheets(3)
      .Application.ScreenUpdating = False
      LR = .Cells(.Rows.Count, "A").End(xlUp).Row
      For i = LR To 2 Step -1
         If .Cells(i, 2) = 0 And .Cells(i, 3) = 0 Then
            Rows(i).Delete
         End If
      Next i
      .Application.ScreenUpdating = True
   End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
this works good for me.
deletes any row with a blank cell in column A
deletes any row in column A with ' symbol in the cell

Code:
    'delete blank lines
    Application.ScreenUpdating = False
    For LR = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("A" & LR).Value = "" Or Left(Range("A" & LR), 1) = "`" Then
            Rows(LR).EntireRow.Delete
        End If
    Next LR

i run it from a module, it will check and delete blanks on the active sheet i think
 
Last edited:
Upvote 0
My codes works, except if I do not run it from the active sheet (sheet3). I would like it amended to run from any sheet
 
Upvote 0
My codes works, except if I do not run it from the active sheet (sheet3). I would like it amended to run from any sheet
Code:
 Sub Delete_Zero_Values()
   Dim i As Long
      Application.ScreenUpdating = False
      For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
         If Cells(i, 2) = 0 And Cells(i, 3) = 0 Then Rows(i).Delete
      Next i
      Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the help. Code now works from any sheet
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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