empty autofiltered range

G

Guest

Hi All,
I use the following piece of code (I don't repeat here the declarations):

For each cella in otherrng
Range("A1").Select
Selection.AutoFilter Field:=2, Criteria1:=cella
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0).Resize(txtteljes.Rows.Count -
1, txtteljes.Columns.Count)
On Error Resume Next
Set txtszurt = txtteljes.SpecialCells(xlVisible)
On Error GoTo 0
If Not txtszurt Is Nothing Then
Selection.Delete Shift:=xlUp
End If
Selection.AutoFilter
Next

My problem is that when range txtszurt is empty (I see on the screen that no
rows are selected), the
If Not txtszurt Is Nothing Then
condition is still met, and all rows are deleted.
What's wrong?

Regards,
Stefi
 
D

Dave Peterson

You have a response at your other post.
Hi All,
I use the following piece of code (I don't repeat here the declarations):

For each cella in otherrng
Range("A1").Select
Selection.AutoFilter Field:=2, Criteria1:=cella
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0).Resize(txtteljes.Rows.Count -
1, txtteljes.Columns.Count)
On Error Resume Next
Set txtszurt = txtteljes.SpecialCells(xlVisible)
On Error GoTo 0
If Not txtszurt Is Nothing Then
Selection.Delete Shift:=xlUp
End If
Selection.AutoFilter
Next

My problem is that when range txtszurt is empty (I see on the screen that no
rows are selected), the
If Not txtszurt Is Nothing Then
condition is still met, and all rows are deleted.
What's wrong?

Regards,
Stefi
 
G

Guest

I repeat here Dave Peterson's solution:
Put line
Set szurtrng = Nothing
before
On Error Resume Next
statement!
Stefi


„malik641†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top