
Originally Posted by
nironto
Hi All,
I have this script that deletes the rows of records if Column A does not have any value. (Not checked).
There are columns A - H. Column A is used for me to indicate if I want to keep the row by inputting any value.
While it works, the issue is that it takes a long time to process and 20000 records can easily take more than 10 mins.
Is there more efficient way that anyone knows of?
...
...
Regards,
Nironto
try this
Sub delete_unwanted_rows()
Dim lr&, lc&, q&
lr = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
lc = Cells.Find("*", searchorder:=xlByColumns, searchdirection:=xlPrevious).Column + 1
With Cells(1).Resize(lr)
.Offset(, lc - 1) = Evaluate("if(" & .Address & "="""","""",1)")
.Resize(, lc).Sort Cells(lc), Header:=xlNo
q = Application.Count(.Offset(, lc - 1))
If q < lr Then Range(Cells(q + 1, 1), Cells(lr, lc - 1)).ClearContents
.Offset(, lc - 1).ClearContents
End With
End Sub
Bookmarks