VBA delete row if cell value found in range

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
125
Hi,

I'm trying to delete any rows that match any name found within another range.

I've used the basis of a code that leaves any column if its in the range but struggling.

VBA Code:
Dim NTS_LR As Long, NTS_LC As Long
        Dim NTS_Name As Variant
        
            With Sheets("NonTechStaff")
                NTS_LR = .Cells(.Rows.Count, 2).End(xlUp).Row
                NTS_Name = .Cells(2, 2).Resize(NTS_LR, 2).Value
            End With
        
        Dim TempLR
        TempLR = Cells(Rows.Count, 1).End(xlUp).Row
        
            For Row = TempLR To 5 Step -1
                x = ""
                On Error Resume Next
                x = WorksheetFunction.Match(Cells(Row, 1), NTS_Name, 0)
                If Not IsNumeric(x) Then Rows(Row).EntireRow.Delete
            Next Row

I think this is the line
Code:
If Not IsNumeric(x) Then Rows(Row).EntireRow.Delete
that I need to amend but not sure how to write the If statement for it
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:

VBA Code:
Sub deleterow()
  Dim f As Range, i As Long
  
  Application.ScreenUpdating = False
  For i = Range("A" & Rows.Count).End(3).Row To 5 Step -1
    Set f = Sheets("NonTechStaff").Range("B:B").Find(Range("A" & i).Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then Rows(i).Delete
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,294
Messages
6,124,101
Members
449,142
Latest member
championbowler

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