
Originally Posted by
vivekchha
...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ThisWorkbook.Activate
Worksheets("AllDeps").Activate
With Worksheets("AllDeps")
Dim i As Integer
For i = 2 To 19
If .Range("M" & i) = "Reject it" Then
Rows(i).EntireRow.Delete
End If
Next
End With
End Sub
Code tags are required when displaying code, please use them.
Your code is in the worksheet module, there would be no reason to activate the workbook because you are already in the workbook, same goes for activating the sheet.
Give this a try..... Put it in a regular module, see my signature if you don't know where the code goes.
Sub Delete_RejectIt()
Dim Rws As Long, Rng As Range
Rws = Cells(Rows.Count, "M").End(xlUp).Row
Set Rng = Range(Cells(2, "M"), Cells(Rws, "M"))
Columns("M:M").AutoFilter Field:=1, Criteria1:="Reject it"
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
ActiveSheet.AutoFilterMode = 0
End Sub
Bookmarks