View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
esmagol esmagol is offline
external usenet poster
 
Posts: 3
Default Filter, Delete and Error handling - need help

On Oct 21, 2:27*pm, Per Jessen wrote:
This should do it:

Sub tester3()
Dim FilterRng As Range
Dim rng As Range

Sheets("New").Select
*Range("A1:D1").AutoFilter Field:=2, Criteria1:=120 'creteria is
filter range)

Set rng = ActiveSheet.AutoFilter.Range

If rng.SpecialCells(xlVisible).Rows.Count 1 Then
* * Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
* * Set rng = rng.Columns(1).SpecialCells(xlVisible).EntireRow
* * rng.Delete
End If

ActiveSheet.AutoFilterMode = False 'deactivate filter
End Sub

Regards,
Per

On 20 Okt., 05:56, esmagol wrote:



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("A1:D1") '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- Hide quoted text -


- Show quoted text -


Thanks Per for the reply. I'm still encountering the same error, hope
I can fix it. Thanks again.