Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default autofilter on a not-active sheet

Hello everyone,

I screwed something up that worked just fine earlier on but now it no longer
does.

This line of code still works from the immediate window, even though the
range is on a not-active sheet:

Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4

Criteria1 in my original code is actually a string-variable, which is also
named HeaderWeek. Since the original code failed, I hard-coded Criteria1 to
"4" (or just 4, doesn't matter from the immediate window where it does
work), but still it doesn't work in the original code. The error I get is:

Method 'Range' of object '_Worksheet' failed.

BTW This code is located in a Worksheet_Change event, if that has any
bearing on this situation.

Greetings,
Peter


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default autofilter on a not-active sheet

Hi Peter,

Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4


Try Qualifying the range:

Me.Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4

---
Regards,
Norman



"Peter" wrote in message
...
Hello everyone,

I screwed something up that worked just fine earlier on but now it no
longer
does.

This line of code still works from the immediate window, even though the
range is on a not-active sheet:

Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4

Criteria1 in my original code is actually a string-variable, which is also
named HeaderWeek. Since the original code failed, I hard-coded Criteria1
to
"4" (or just 4, doesn't matter from the immediate window where it does
work), but still it doesn't work in the original code. The error I get is:

Method 'Range' of object '_Worksheet' failed.

BTW This code is located in a Worksheet_Change event, if that has any
bearing on this situation.

Greetings,
Peter




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default autofilter on a not-active sheet

If it's on a different worksheet than the one that owns the code, I bet you did
something like this first:

worksheets("othersheet").select
Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4

That unqualified range object refers to the worksheet that owns the code when
you're in that worksheet's code module.

You could use:

worksheets("othersheet").select
worksheets("Othersheet").Range("HeaderWeek").AutoF ilter Field:=3, Criteria1:=4

or even drop the .select and just work on the range directly:

worksheets("othersheet").Range("HeaderWeek").AutoF ilter Field:=3, Criteria1:=4



Peter wrote:

Hello everyone,

I screwed something up that worked just fine earlier on but now it no longer
does.

This line of code still works from the immediate window, even though the
range is on a not-active sheet:

Range("HeaderWeek").AutoFilter Field:=3, Criteria1:=4

Criteria1 in my original code is actually a string-variable, which is also
named HeaderWeek. Since the original code failed, I hard-coded Criteria1 to
"4" (or just 4, doesn't matter from the immediate window where it does
work), but still it doesn't work in the original code. The error I get is:

Method 'Range' of object '_Worksheet' failed.

BTW This code is located in a Worksheet_Change event, if that has any
bearing on this situation.

Greetings,
Peter


--

Dave Peterson
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
Copy sheet and make new sheet active belvy123 Excel Discussion (Misc queries) 5 April 24th 08 03:33 PM
Active Cell Copy And Paste Sheet to Sheet A.R.J Allan Jefferys New Users to Excel 4 May 4th 06 02:04 AM
Using the Active cell in one sheet for another sheet JOHNNY_E Excel Discussion (Misc queries) 0 May 4th 05 06:19 AM
How to count rows in a user-defined AutoFilter or AdvancedFilter is active? Frank Krogh Excel Programming 1 February 26th 04 11:08 AM
How to make a sheet the active sheet? [email protected] Excel Programming 1 October 26th 03 12:25 AM


All times are GMT +1. The time now is 03:24 PM.

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

About Us

"It's about Microsoft Excel"