Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default AutoFilter method of Range Class Failed

STR is a function in VBA.

Perhaps you should change your variable to

Dim sStr as String

and use that.

Can't say it is your problem, but it may be.

--
Regards,
Tom Ogilvy

"Randy Reese" wrote in message
ink.net...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default AutoFilter method of Range Class Failed

Thanks Tom, but it didn't fix problem. :( Any further help would be
appreciated.

"Tom Ogilvy" wrote in message
...
STR is a function in VBA.

Perhaps you should change your variable to

Dim sStr as String

and use that.

Can't say it is your problem, but it may be.

--
Regards,
Tom Ogilvy

"Randy Reese" wrote in message
ink.net...
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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default AutoFilter method of Range Class Failed

Fixed, it was the .takefocusonclick property.

Thanks Tom.
"Randy Reese" wrote in message
nk.net...
Thanks Tom, but it didn't fix problem. :( Any further help would be
appreciated.

"Tom Ogilvy" wrote in message
...
STR is a function in VBA.

Perhaps you should change your variable to

Dim sStr as String

and use that.

Can't say it is your problem, but it may be.

--
Regards,
Tom Ogilvy

"Randy Reese" wrote in message
ink.net...
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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill method of range class failed Don Guillett Excel Discussion (Misc queries) 0 February 27th 08 03:56 PM
Autofill method of range class failed Appache Excel Discussion (Misc queries) 5 February 27th 08 03:37 PM
AutoFit method of Range class failed Wellie[_2_] Excel Programming 1 February 29th 04 02:06 PM
VB Error: Paste Special method of range class failed Chris Excel Programming 2 January 30th 04 12:51 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"