[英]Advanced Filter Excel VBA
I have created a dynamic list range for my advanced filter. 我为我的高级过滤器创建了一个动态列表范围。 I have created name called "Data".
我创建了名为“数据”的名称。 When I try to input the name into the VBA formula I receive an error.
当我尝试在VBA公式中输入名称时,收到错误消息。 The dynamic names work for the criteria and the output range?
动态名称适用于条件和输出范围?
Range("Sheet2!Data").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range _
("Sheet2!Filter"), CopyToRange:=Range("Sheet2!Location"), Unique:=False
I receive the following run-time error '1004': 我收到以下运行时错误“ 1004”:
Method 'Range' of object'_Global' failed
对象“ _Global”的方法“范围”失败
If your Named Ranges' scope is for Sheet2
only, then you need to fully qualify the Range
with Worksheets("Sheet2")
, as in the code below: 如果“命名范围”的范围仅适用于
Sheet2
,则需要使用Worksheets("Sheet2")
完全限定Range
,如以下代码所示:
With Worksheets("Sheet2")
.Range("Data").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range("Filter"), _
CopyToRange:=.Range("Location"), Unique:=False
End With
If your Named Ranges' scope is Workbook
then use the code below (there's no need to qualify the Range
with the Worksheet
): 如果您的“命名范围”的范围是“
Workbook
则使用下面的代码(无需使用“ Worksheet
限定Range
):
Range("Data").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("Filter"), _
CopyToRange:=Range("Location"), Unique:=False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.