Autofilter error handler not working??

wiegs187

Board Regular
Joined
May 27, 2007
Messages
81
I have the following code to use auto filter to delete rows that have CusOrd in column B.

With ActiveSheet
.AutoFilterMode = False
With Range("B3", Range("B" & Rows.Count).End(xlUp))
.AutoFilter 1, "*CusOrd*"
On Error Resume Next
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
On Error GoTo 0
End With
.AutoFilterMode = False
End With


If there are no "CusOrd" to delete I get an error, even though I have the "On Error Resume Next". What is going wrong? I don't really know what the "On Error GoTo 0" means, I got this code from this message board. It was working great on everything up until this issue.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try this modification

Code:
Sub test()
With Range("B3", Range("B" & Rows.Count).End(xlUp))
.AutoFilter 1, "" * CusOrd * ""
On Error Resume Next
With .Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
If WorksheetFunction.CountA(.Columns("A:A")) = 0 Then GoTo autofilterexit
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
autofilterexit:
.AutoFilter
End With
End Sub

for explanation of "on error goto0" see this explanation by Pearson

http://www.cpearson.com/excel/errorhandling.htm
 
Upvote 0
If you are getting an error on the delete line, then I would assume you have your VBE set to break on all errors (Tools-Options, General tab in the VBEditor)
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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