[英]Recorded VBA macro - run time error 1004 autofilter method of range class failed
I recorded a simple macro to autofilter some pivot data columns by setting up the autofilter on the pivot header line.我录制了一个简单的宏,通过在枢轴标题行上设置自动过滤器来自动过滤一些枢轴数据列。
Here is the code(highlighted where the apparent error is):这是代码(突出显示明显错误的位置):
Sub Only_Choose_Unders()
' Only_Choose_Unders Macro
Sheets("Lab UP no 360 Chem OPP").Select
Range("K24").Select
Selection.AutoFilter
**ActiveSheet.Range("$B$24:$J$3296").AutoFilter Field:=8, Criteria1:="<0", _
Operator:=xlAnd**
ActiveSheet.Range("$B$24:$J$3296").AutoFilter Field:=9, Criteria1:="<0", _
Operator:=xlAnd
End Sub
Many thanks everyone, Eyal非常感谢大家,Eyal
Operator:=xlAnd
is for multi criteria autofilters (within the same field). Operator:=xlAnd
用于多条件自动Operator:=xlAnd
器(在同一字段内)。
You want to leave the operator blank and it will filter on both fields.您希望将运算符留空,它将对两个字段进行过滤。
I also removed the selections, they aren't necessary.我也删除了选择,它们不是必需的。
Sub Only_Choose_Unders()
' Only_Choose_Unders Macro
With Sheets("Lab UP no 360 Chem OPP").Range("B24:J3296")
.AutoFilter Field:=8, Criteria1:="<0"
.AutoFilter Field:=9, Criteria1:="<0"
End With
End Sub
As a heads-up the Field
parameter is indexed relative to the range given.作为提示, Field
参数是相对于给定范围进行索引的。 So Field:=8
in this instance will be Column I, if that was supposed to be Column H you would want Field:=7
所以Field:=8
在这种情况下将是第 I 列,如果它应该是第 H 列,你会想要Field:=7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.