Hi all,
I have a spreadsheet that has nearly 50,000 rows. In column J of this sheet, values are either "TRUE" or "FALSE." I am trying to delete every row in which the cell in column J is "FALSE." The following code works but it takes over three minutes to compile.
I figured AutoFiltering would be quicker than looping but it is still taking way too long. Am I stuck here so is there a faster method? Thanks for the help!
I have a spreadsheet that has nearly 50,000 rows. In column J of this sheet, values are either "TRUE" or "FALSE." I am trying to delete every row in which the cell in column J is "FALSE." The following code works but it takes over three minutes to compile.
Code:
Sub Delete_Rows()
Dim ws As Worksheet
Dim rng As Range
Dim lastRow As Long
Set ws = ActiveWorkbook.Sheets("Sheet1")
lastRow = ws.Range("J" & ws.Rows.Count).End(xlUp).Row
Set rng = ws.Range("J1:J" & lastRow)
With rng
.AutoFilter Field:=1, Criteria1:="FALSE"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ws.AutoFilterMode = False
End Sub
I figured AutoFiltering would be quicker than looping but it is still taking way too long. Am I stuck here so is there a faster method? Thanks for the help!