Delete cells specific to names

vbanoob123

New Member
Joined
Mar 22, 2016
Messages
3
Hello Everybody,

I have an excel file where I would like to delete rows if a list names appear in either column L or M.

Would anybody know what VBA is required for this please?

Thank you for your help.

Noob
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
VBA is not really required as you can simply activate the autofilter feature, apply the criteria to extract the records to delete and then select all rows and delete. Do this for criteria in column L and M and the resulting list will be cleaned from the unwanted records.
 
Upvote 0
Hi rudi,

This file is going to be looked at everyday and edited, there are about six names that need to be excluded across two columns and then delete the rows. Isn't there a faster way than doing this manually?

I did try this code from another discussion on here

Private Sub CommandButton1_Click()


With ActiveSheet
.AutoFilterMode = False
With Range("l11", Range("L" & Rows.Count).End(xlUp))
.AutoFilter 1, "*John_Smith*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With


End Sub

---

But this only looks across one column and deletes only rows with John Smith, what happens if i wanted to exclude more like Daniel Adams & Joe Bloggs?

Many Thanks,

Noob
 
Upvote 0
Try this...
Modify the code and criteria as required...

Code:
Sub FilterAndDeleteData()
    'Filter for column L (list names in Criteria line)
    ActiveSheet.Range("A1").CurrentRegion.AutoFilter _
        Field:=12, _
        Criteria1:=Array("Janet Leverling", "Margaret Peacock"), _
        Operator:=xlFilterValues
    With ActiveSheet.AutoFilter.Range
        On Error Resume Next
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        On Error GoTo 0
    End With
    ActiveSheet.AutoFilterMode = False
    'Filter for column M (list names in Criteria line)
    ActiveSheet.Range("A1").CurrentRegion.AutoFilter _
        Field:=13, _
        Criteria1:=Array("Road", "Sea"), _
        Operator:=xlFilterValues
    With ActiveSheet.AutoFilter.Range
        On Error Resume Next
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        On Error GoTo 0
    End With
    ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,657
Members
449,247
Latest member
wingedshoes

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