excel - 过滤条件仅获取数组中的第一个值
问题描述
我在工作表 3 上使用值列表,然后从 (strArray) 构建一个数组
' ADDS ALL ROWS FROM SHEET3 TO A ARRAY
With Worksheets(3)
TotalRows = .Range("A" & .Rows.Count).End(xlUp).Row
strArray = .Range("A1:A" & TotalRows).Value
MsgBox UBound(strArray)
'Debug.Print Join(strArray, ", ")
End With
在此之后,我尝试使用以下代码过滤我的数据:
With Worksheets(1)
.Columns("A").AutoFilter Field:=1, Criteria1:=strArray, Operator:=xlFilterValues
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A1:A" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Sheets(2).Range("A1")
End With
发生的情况是它只过滤数组中的第一个值。但是,如果我将strArray更改为array("test", "test")例如,它可以正常工作并根据数组中的所有值构建标准。
为什么会出现这种情况?
完整代码:
Dim strArray As Variant
Dim TotalRows As Long
Dim LastRow As Long
' ADDS ALL ROWS FROM SHEET3 TO A ARRAY
With Worksheets(3)
TotalRows = .Range("A" & .Rows.Count).End(xlUp).Row
strArray = .Range("A1:A" & TotalRows).Value
MsgBox UBound(strArray)
'Debug.Print Join(strArray, ", ")
End With
With Worksheets(1)
.Columns("A").AutoFilter Field:=1, Criteria1:=strArray, Operator:=xlFilterValues
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A1:A" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Sheets(2).Range("A1")
End With
解决方案
推荐阅读
- angularjs - IHttpPromise<{}>,可观察的
如何使它在http调用中工作? - python - GRU 相同的配置但以两种不同的方式在 tensorflow 中产生两种不同的输出
- database-performance - 逻辑或物理删除在 Spanner 中的性能更好吗?
- sql - 试图找到介于两者之间
- xaml - 自定义对象的 Xaml 定义仅适用于第一个实例
- android - 顶级 build.gradle 文件中的 ext 属性
- c++ - C++11:没有复制构造函数的自定义基于范围的循环
- javascript - AVG(COLUMN_SCORE) 未写入 SQLite 数据库
- elasticsearch - 用于弹性搜索的 kubernetes 滚动更新
- networking - GKE Pod 连接到同一子网中的外部虚拟机