首页 > 解决方案 > 在自动过滤器中使用数组

问题描述

rname 是我动态初始化的数组。

我在 vba 代码中得到了这个

运行时错误“1004”:应用程序定义或对象定义错误

For z=2 to lr2
    k=0
    if sh3.Cells(z,2)>1 Then
        size=sh3.Cells(z,2).value2-1
        Redim rname(size)
        Do While z<z+sh3.Cells(z,2).value2 And k<sh3.Cells(z,2).value2-1
            z=z+1
            rname(k)=sh3.Cells(z,1).value2
            k=k+1
        Loop
        With sh1.Range("A3")
            .AutoFilter Field:=14, Criteria1:= sh.Cells(x,2).value2
            .AutoFilter Field:=4, Criteria1:=rname()
        End With

标签: excelvbaautofilter

解决方案


我认为您AutoFilter需要知道XlAutoFilterOperator您的标准使用什么。试试看,请修改:

.AutoFilter Field:=4, Criteria1:=rname(), Operator:=xlFilterValues

推荐阅读