after autofilter/delete rows left not visible

J

John Keith

I am using an autofilter to select rows that I want to delete, then
delete them, I then turn off the autofilter and select cell A2 and
enable screenupdating. But at the end of executing this code row A2 is
not visible, rather a row much lower (608 actually) is visible in the
window. How do I get row A2 to be visible in the window?


Dim rTable As Range
Range("A1").Select
With Selection
If .Cells.Count > 1 Then
Set rTable = Selection
Else
Set rTable = .CurrentRegion
On Error GoTo 0
End If
End With

Range("A2").Select
ActiveSheet.AutoFilterMode = False

' Delete all rows that are NOT for year 2005

rTable.AutoFilter Field:=2, Criteria1:="<>*"2005"*",
Operator:=xlAnd
rTable.Offset(1,
0).SpecialCells(xlCellTypeVisible).EntireRow.Delete

Range("A1").Select
ActiveSheet.AutoFilterMode = False
Range("A2").Select
Application.ScreenUpdating = True

John Keith
(e-mail address removed)
 
D

Don Guillett

Try this. I corrected for word wrap on the code lines
Sub filterit()
On Error Resume Next
lr = Cells.Find("*", Cells(Rows.Count, Columns.Count) _
, , , xlByRows, xlPrevious).Row

Range("a1:c" & lr).AutoFilter Field:=2, _
Criteria1:="<>2005"

Range("a2:c" & lr).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete

Range("a1:c" & lr).AutoFilter
End Sub
 

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