Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Runtime Error 1004


I have a user form with the following code and while the code is running
I received a RunTime Error 1004 - Method 'select' of object'_worksheet
failed. My code is set up to bring up a user form where I type a name
and press Get Data. The code should run through each worksheets and
autofilter the name that I typed in the user form. The code apears to
work - actually filters the last sheet and then the Runtime Error pops
up.

Private Sub cmdFilter_Click()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
sh.Select
Range("A2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=tbName
Next sh

Unload Me
Sheet1.Select
End Sub

Any help is appreciated. :(


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=483313

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Runtime Error 1004


try sheet1.activate

--
RPIJ
-----------------------------------------------------------------------
RPIJG's Profile: http://www.excelforum.com/member.php...nfo&userid=928
View this thread: http://www.excelforum.com/showthread.php?threadid=48331

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Runtime Error 1004


I'm not sure what you're suggesting; will you elaborate?


--
Lizz45ie


------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=483313

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Runtime Error 1004


replace sheet1.select with sheet1.activat

--
RPIJ
-----------------------------------------------------------------------
RPIJG's Profile: http://www.excelforum.com/member.php...nfo&userid=928
View this thread: http://www.excelforum.com/showthread.php?threadid=48331

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Runtime Error 1004

You are best off to avoid the selects all together... They can be
problematic. Try this code...

Private Sub cmdFilter_Click()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
with sh.Range("A2")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=tbName
end with
Next sh

Unload Me
End Sub


--
HTH...

Jim Thomlinson


"Lizz45ie" wrote:


I have a user form with the following code and while the code is running
I received a RunTime Error 1004 - Method 'select' of object'_worksheet
failed. My code is set up to bring up a user form where I type a name
and press Get Data. The code should run through each worksheets and
autofilter the name that I typed in the user form. The code apears to
work - actually filters the last sheet and then the Runtime Error pops
up.

Private Sub cmdFilter_Click()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
sh.Select
Range("A2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=tbName
Next sh

Unload Me
Sheet1.Select
End Sub

Any help is appreciated. :(


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=483313


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
runtime error 1004 valdesd Excel Discussion (Misc queries) 0 October 12th 05 05:30 PM
Runtime error 1004 Daniel Excel Programming 2 July 19th 05 04:37 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
What is RunTime Error '1004'? Ed Excel Programming 3 November 18th 04 07:09 PM
runtime error 1004 marta Excel Programming 0 July 22nd 04 02:25 PM


All times are GMT +1. The time now is 10:40 AM.

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"