Delete Rows based on data in Column

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
The below is working fine to delete the rows based on the condition in column N . However, it takes too long if one has 10,000+ rows of data.

Sub Delete()
Last = Cells(Rows.Count, "N").End(xlUp).Row
For i = Last To 3 Step -1
If (Cells(i, "N").Value) <> "NOT ON FILE" Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "N").EntireRow.Delete
End If
Next i
End Sub





I have tried the below code but it appears to be stuck on the code - Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete.
Any ideas?

With ActiveSheet.UsedRange
.AutoFilter 14, "=NOT ON FILE"
.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub


Also, I've tried using the auto filter method to delete every row that doesn't contain "NOT ON FILE", so failing to get this working
Rows("2:2").AutoFilter Field:=14, Criteria1:="NOT ON FILE", VisibleDropDown:=False
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about
VBA Code:
Sub mrsushi()
   With ActiveSheet
      .Range("A2:N2").AutoFilter 14, "Not on file"
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub mrsushi()
   With ActiveSheet
      .Range("A2:N2").AutoFilter 14, "Not on file"
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
End Sub


That's done the trick. However, I need to keep the rows that contain "Not on file". Every other row has deleted so I need it to work the other way
 
Upvote 0
In that case use
VBA Code:
.Range("A2:N2").AutoFilter 14, "<>Not on file"
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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