简体   繁体   English

无法使用数组使用多个条件自动过滤列

[英]Not able to autofilter the Column with multiple criteria using array

I am trying to Autofilter a column with multiple criteria. 我正在尝试自动筛选具有多个条件的列。 Autofilter is only working with one data, but not with multiple data. 自动筛选器仅处理一个数据,而不处理多个数据。

For lb1fil = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lb1fil) = True Then
    strarray = Chr(34) & ListBox1.list(lb1fil) & Chr(34) & "," & strarray
End If
Next
Debug.Print Left(strarray, Len(strarray) - 1)
Worksheets("Result").Activate
Range("L4:L2000").AutoFilter Field:=1, Criteria1:=Array(Left(strarray, 
Len(strarray) - 1)), Operator:=xlFilterValues

Please let me know if there is any alternative way or something I have missed. 请让我知道是否还有其他替代方法或我错过的东西。

I searched SO for solution but none of them are working. 我在SO中寻找解决方案,但没有一个在工作。

I got the answer after RND, (Thanks to SO) 在RND之后我得到了答案,(谢谢)

For lb1fil = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lb1fil) = True Then
    'strarray = Chr(34) & ListBox1.list(lb1fil) & Chr(34) & ", " & strarray
    strarray = strarray & "," & ListBox1.list(lb1fil)
End If
Next
 Debug.Print Right(strarray, Len(strarray) - 1)
 strlen = Right(strarray, Len(strarray) - 1)
Debug.Print strlen

ary = Split(strlen, ",")

Worksheets("Result").Activate
Range("L4:L2000").Select
Selection.AutoFilter
Range("L4").Activate
ActiveSheet.Range("$L$4:$L$2000").AutoFilter Field:=1, Criteria1:=Array( _
    ary), Operator:=xlFilterValues

I have added array using split, and it worked. 我已经使用split添加了数组,并且它起作用了。

PLease note the solution is from another question and the solution is not mine. 请注意,该解决方案来自另一个问题,而该解决方案不是我的。 So wanted to share that. 所以想分享。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM