简体   繁体   English

录制的 VBA 宏 - 运行时错误 1004 范围类的自动过滤方法失败

[英]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.

相关问题 运行时错误1004 - 范围类的自动过滤方法失败 - Run-time error 1004 - Autofilter Method of Range Class Failed 运行时错误“1004”:范围类的自动过滤方法失败 - run-time error '1004': Autofilter method of range class failed 运行时错误&#39;1004-Range类的AutoFilter方法失败 - Run-Time error '1004 - AutoFilter method of Range class failed 运行时错误“1004”--范围类的自动过滤方法失败 - Run-time Error '1004'-- AutoFilter Method of Range Class Failed Excel VBA 运行时错误 1004 范围 class 的自动筛选方法失败 - 出了什么问题? - Excel VBA Run Time Error 1004 AutoFilter method of Range class failed - what is wrong? VBA运行时错误&#39;1004&#39;。 Range类的AutoFilter方法失败 - VBA Runtime error '1004'. AutoFilter method of Range class failed 运行时错误“ 1004”:范围类的VBA选择方法失败 - Run Time Error '1004': Select method of Range Class failed VBA VBA 运行时错误 1004 Range 类的排序方法失败 - VBA Run time error 1004 Sort Method of Range class failed 错误信息 Run time error 1004 Autofilter method or range class failed - Error message Run time error 1004 Autofilter method or range class failed VBA:为什么自动过滤器在手动过滤器时不起作用? (运行时错误&#39;1004&#39;:对象&#39;Range&#39;的方法&#39;AutoFilter&#39;失败) - VBA: Why will Autofilter not work when manual filter does? (Run-time error '1004': Method 'AutoFilter' of object 'Range' failed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM