ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   after autofilter/delete rows left not visible (https://www.excelbanter.com/excel-programming/422380-after-autofilter-delete-rows-left-not-visible.html)

John Keith

after autofilter/delete rows left not visible
 
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.Delet e

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

John Keith


Don Guillett

after autofilter/delete rows left not visible
 
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"John Keith" wrote in message
...
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.Delet e

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

John Keith




All times are GMT +1. The time now is 02:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com