Advanced Filter whit named ranges macro (Error 1004)

Caliche

Active Member
Joined
Mar 26, 2002
Messages
339
In the following macro I am getting 1004 error (Failure in Advanced Filter Method of Range Class). I have been told that for Advanced Filter your ranges must be in the same workbook, and that you can avoid this situation using named ranges, as in my case, where criteria and "copy to" ranges are in a workbook (Disp_Dem.xls in OF worksheet), and data range is in another workbook (Trabajo.xls).

Here is my code.

Sub Cons_Ord()
'
' Order Filter
'
Workbooks("Disp_Dem").Activate
Worksheets("OF").Select
Range("Crit_Lanz").Select
Range("Trabajo.xls!Datos_lanz").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Disp_Dem.xls!Crit_Lanz"), CopyToRange:=Range("Disp_Dem.xls!Rango_Lanz"), Unique:=False

End Sub

Any suggestions in order to avoid this error?.

Thanks in advance.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
On 2002-04-24 11:33, Caliche wrote:
In the following macro I am getting 1004 error (Failure in Advanced Filter Method of Range Class). I have been told that for Advanced Filter your ranges must be in the same workbook, and that you can avoid this situation using named ranges...

While it's true that the "Copy to" reference must be on the same worksheet when you're using Excel's Data | Filter | Advanced Filter... menu command, it's not the case for a macro. You don't need an named range.
 
Upvote 0
error 1004 is common, i guess down to the named ranges that refer to in VBA, this error is conflict of some kind..
 
Upvote 0

Forum statistics

Threads
1,214,556
Messages
6,120,190
Members
448,949
Latest member
keycalinc

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top