E
esmagol
Hi everyone,
I am doing various filter and delete routine in one of my worksheet to
finish my report. I am planning to successively run those routines to
save time. My problem is when one of my filter and delete routine
cannot match its criteria vba will return Run-time error '1004'. I
want to have an error handling that will call the next routine should
vba encountered this error and if not that much a simple message box
that this particular routine resulted to an error and will ask if the
user want to continue running the macro or not. Below is one of my
basic filter and delete routine (got it here also .
Have a nice day! Thanks everyone for your time
Sub tester2()
Dim rng As Range
Sheets("New").Select
Application.Goto Reference:=Range("A11") 'Range for names
Selection.AutoFilter
Selection.AutoFilter Field:=2, _
Criteria1:=120 'creteria is filter range
'ActiveSheet.Range("$A$6:$AE$21893").AutoFilter Field:=15,
Criteria1:="=120" _
, Operator:=xlOr, Criteria2:="=420"
'use Operator:=xlor if more than one criteria
Set rng = ActiveSheet.AutoFilter.Range
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
Set rng = rng.Columns(1).SpecialCells(xlVisible).EntireRow
rng.Delete
ActiveSheet.AutoFilterMode = False 'deactivate filter
End Sub
I am doing various filter and delete routine in one of my worksheet to
finish my report. I am planning to successively run those routines to
save time. My problem is when one of my filter and delete routine
cannot match its criteria vba will return Run-time error '1004'. I
want to have an error handling that will call the next routine should
vba encountered this error and if not that much a simple message box
that this particular routine resulted to an error and will ask if the
user want to continue running the macro or not. Below is one of my
basic filter and delete routine (got it here also .
Have a nice day! Thanks everyone for your time
Sub tester2()
Dim rng As Range
Sheets("New").Select
Application.Goto Reference:=Range("A11") 'Range for names
Selection.AutoFilter
Selection.AutoFilter Field:=2, _
Criteria1:=120 'creteria is filter range
'ActiveSheet.Range("$A$6:$AE$21893").AutoFilter Field:=15,
Criteria1:="=120" _
, Operator:=xlOr, Criteria2:="=420"
'use Operator:=xlor if more than one criteria
Set rng = ActiveSheet.AutoFilter.Range
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
Set rng = rng.Columns(1).SpecialCells(xlVisible).EntireRow
rng.Delete
ActiveSheet.AutoFilterMode = False 'deactivate filter
End Sub