VBA to delete entire row based on certain filters

AEL8871

New Member
Joined
Nov 19, 2015
Messages
23
I have a bunch of filters I'd like to automate on a spreadsheet. All based on a Yes/No/Blank cell value

For example:
If Column N contains "No" in any row, delete the entire row.
If Column J contains "Yes" in any row, delete the entire row.
If Column K contains blanks in any row, delete the entire row.
If column M contains "No" in any row, delete the entire row.
In column L contains "Yes" in any row, delete the entire row
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hello AEL8871,

This may work for you but based on the following assumptions (as you haven't explained the set out of your worksheet):-

- Data is in Sheet1(this is the sheet code not sheet name).
- Headings are in row1 with data starting in row2.
- The column range is A:P.
- Column Q can be used as a helper column to determine that the criteria exists in each row for Columns J, K, L, M, N. This is done with a temporarily inserted formula.

VBA Code:
Sub Test()

        Dim lr As Long: lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

Application.ScreenUpdating = False

        Sheet1.Range("Q2:Q" & lr).Formula = "=SUM(COUNTIF(A2:P2,{""Yes"",""No"",""""}))"

        With Sheet1.[A1].CurrentRegion
                .AutoFilter 17, ">0"
                .Offset(1).EntireRow.Delete
                .AutoFilter
        End With

        Sheet1.Columns(17).Clear

Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Try this revision of Fluff's code:
VBA Code:
Sub Delrws()
    Dim ary As Variant, i As Long
    ary = Array("No", "Yes")
    With Range("J:N")
        For i = 0 To UBound(ary)
           .Replace ary(i), ""
        Next i
        For i = 10 To 14
          Columns(i).SpecialCells(xlBlanks).EntireRow.Delete
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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