Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Laurence Lombard
 
Posts: n/a
Default Using named ranges in AdvacendFilter statement

The statement
Sheets("Cash Bks").Range("CashBookData").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Range("DieselCriteria"), _
CopyToRange:=Range("DieselOutputRange"), Unique:=False

works but it gives the error "Method 'Range' of object '_Worksheet' failed"
without the Sheets("Cash Bks") part as in

Range("CashBookData").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Range("DieselCriteria"), _
CopyToRange:=Range("DieselOutputRange"), Unique:=False

The named range "CashbookData" refers to a range in another worksheet. I
would like to exclude the Sheets("Cash Bks") part from the VBA statement as
I want to make this sheet more adaptable ie not have to change the VBA code
if the workbook that CashBookData resides in changes. Is there a way to work
around this?

Thanks in advance
Laurence Lombard


  #2   Report Post  
Debra Dalgleish
 
Posts: n/a
Default

If it's a workbook level name, you could do the following:

Dim rngList As Range
Set rngList = ActiveWorkbook.Names("CashBookData").RefersToRange

rngList.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("DieselCriteria"), _
CopyToRange:=Range("DieselOutputRange"), Unique:=False


Laurence Lombard wrote:
The statement
Sheets("Cash Bks").Range("CashBookData").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Range("DieselCriteria"), _
CopyToRange:=Range("DieselOutputRange"), Unique:=False

works but it gives the error "Method 'Range' of object '_Worksheet' failed"
without the Sheets("Cash Bks") part as in

Range("CashBookData").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Range("DieselCriteria"), _
CopyToRange:=Range("DieselOutputRange"), Unique:=False

The named range "CashbookData" refers to a range in another worksheet. I
would like to exclude the Sheets("Cash Bks") part from the VBA statement as
I want to make this sheet more adaptable ie not have to change the VBA code
if the workbook that CashBookData resides in changes. Is there a way to work
around this?

Thanks in advance
Laurence Lombard




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
Macro (Print) - Calling Named Ranges KGlennC Excel Discussion (Misc queries) 1 March 19th 05 09:20 PM
Named Ranges Donna Excel Discussion (Misc queries) 3 February 1st 05 11:35 PM
Poor Workbook Performance due to Named Ranges jrusso Excel Discussion (Misc queries) 2 January 10th 05 11:39 PM
Named dynamic ranges, copied worksheets and graph source data WP Charts and Charting in Excel 1 November 28th 04 05:19 PM


All times are GMT +1. The time now is 11:50 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"