View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Randy Reese Randy Reese is offline
external usenet poster
 
Posts: 14
Default AutoFilter method of Range Class Failed

I keep getting an error "AutoFilter method of Range Class Failed" when I run
this sub. I have data in B1:F232. Can someone help me, please
----------------------------------------------------------------------------
Sub test()
Dim rng As Range
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim Str As String
Dim LRow As Long

Set WS = Sheets("Lod")
Set WS2 = Sheets("Print282")
LRow = LastRow(WS2)
Str = "282"

With WS.Columns("B:F")
.AutoFilter Field:=1, Criteria1:=Str
With WS.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(0, 2).Resize(.Rows.Count - 1, 3) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then
rng.Copy WS2.Range("B" & LRow + 1)
End If
End With
End With
WS.AutoFilterMode = False
End Sub
----------------------------------------------------------------------------
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
after:=sh.Range("B1"), _
lookat:=xlPart, _
LookIn:=xlValues, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False).Row

On Error GoTo 0
End Function