Macro to delete rows used to work fast, but now it has become slow

manojrf

Board Regular
Joined
Mar 28, 2011
Messages
109
Hi there,

Dim LastRow&, FilterRange As Range
With Sheets("KCC - OD")
.AutoFilterMode = False
LastRow = .Cells.Find("*", after:=.Range("B1"), SearchOrder:=xlByRows, searchdirection:=xlPrevious).Row
Set FilterRange = .Range("AB1:AB" & LastRow)
FilterRange.AutoFilter Field:=1, Criteria1:="=2"
On Error Resume Next
FilterRange.SpecialCells(12).EntireRow.Delete
Err.Clear
.AutoFilterMode = False
End With
Set FilterRange = Nothing

First of all let me tell you that I am not an expert in Excel or making macros. I get the knowledge from the members of this forum who are ready to help.

I am using the macro given above to delete rows in a sheet named KCC - OD, when the value in column AB is 2. It was working fine and fast. But nowadays it is **** slow and I don't know why. The sheet has around 2000 rows and 30 columns.

Can anyone help me to make it a bit more fast.

Thank you.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Have calculation-intensive formulas that point to that table been added recently by any chance?
 
Upvote 0
Try
VBA Code:
Sub Macro1()
Dim Lr&, T&, S$
Dim M, b
Application.ScreenUpdating = False
With Sheets("KCC - OD")
Lr = .Range("B" & Rows.Count).End(xlUp).Row
M = Filter(Evaluate("Transpose(If('KCC - OD'!AB1:AB" & Lr & "=2,""A""&Row(AB1:AB" & Lr & "),False))"), False, False)
For T = UBound(M) To 1 Step -1
S = S & "," & M(T)
If Len(S) > 240 Or T = 1 Then
.Range(Mid(S, 2)).EntireRow.Delete
S = ""
End If
Next T
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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