【发布时间】:2021-05-09 06:32:45
【问题描述】:
我有一个表格,我用 vba 命令过滤:
tbl.Range.AutoFilter Field:=11, Criteria1:="=*" & Left(street, 3) & "*", Operator:=xlAnd
这是一个 *contains* 过滤器,BodyRange(目视检查)应该算 7 行,但是这样
tbl.DataBodyRange.SpecialCells(xlCellTypeVisible)
我只检索不到其中的 4 个,它的行为就像 BodyRange.SpecialCells 从过滤器中仅捕获具有过滤器值的开始值而不是包含它的值(如果我的过滤列街道是 "pilsudzki" "al. pilsudzki" "al. gen pilsudzki" BodyRange 将跳过所有的 "al. pilsudzki" 等等...并且只给我 "pilsudzki" 即以 "pils开头的那个>*")
为了解决这个问题,我必须改用这个技巧:
Set rnTble = Sheet1.Range("K2:K150000").SpecialCells(xlCellTypeVisible)
For Each cll In rnTble.Cells
Me.ListBox2.AddItem cll.Value
If cll.Value = "" Then Exit For
Next
然后才捕获所有包含“*pils*”的过滤值
任何想法为什么会这样?
【问题讨论】:
-
参考This。由于该区域被不连续的数据分隔,因此必须使用该区域。