Deleting an entire row based on a cell value?

chuckles1066

Banned
Joined
Dec 20, 2004
Messages
372
I would like to be able to delete an entire row if the value of any cell between row 3 and row 999 in column d equals 0.

I'd like to be able to do this over a range of worksheets, named Jan, Feb, Mar.........Dec.

Is there a quick way?

Many thanks, I am not worthy.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Depending on whether you need to process all sheets in a workbook, or avoid some, I have provided 2 options. Both use the same code to remove unwanted lines, they just loop differently through the sheets.
Code:
Sub ProcessSheets_1()
    'if all sheets in workbook are to be processed
    Dim Sht As Worksheet
    For Each Sht In ActiveWorkbook.Worksheets
        Sht.Activate
        DeleteLines
    Next Sht
End Sub

Sub ProcessSheets_2()
    'if other sheets must be avoided
    Dim Sht As Worksheet
    For Each Sht In ActiveWorkbook.Worksheets
        If Sht.Name = "Other" Or Sht.Name = "Mar" Then
            'do nothing
        Else
            'process
            Sht.Activate
            DeleteLines
        End If
    Next Sht
End Sub

Sub DeleteLines()
    Dim Rw As Long
    For Rw = 999 To 3 Step -1
        If Cells(Rw, 4).Value = 0 Then Cells(Rw, 4).EntireRow.Delete
    Next Rw
End Sub
Denis
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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