在自动筛选中使用数组



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

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

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

最新更新