我有一个包含多列的表,我想使用条件过滤表并接收包含匹配项的范围。 (1) 我知道我可以使用循环轻松地在表中进行迭代,或者 (2) 我可以在列中添加过滤器。
我不喜欢(1),因为表中的迭代太慢,但我可以做到这一点。
Excel 是否有一种函数可以一步返回按特定条件过滤的范围?像“function multipleVlookup(...) As Range”之类的东西
EDIT:回答后我的代码:(感谢亚历山大)
Set tableRange = Range("A1:M" & lastRow)
' Filter
With tableRange
Call .AutoFilter(5, "test1")
Call .AutoFilter(11, "test2")
Call .AutoFilter(9, myDate)
End With
Set filteredRange = tableRange.SpecialCells(xlCellTypeVisible)
' Disable Filter
With tableRange
Call .AutoFilter(5)
Call .AutoFilter(11)
Call .AutoFilter(9)
End With
' Do something with this result
For Each c In f.Cells.Rows
actualRow = c.Row
If actualRow <> 1 Then
' Do something
End If
Next
如果您可以过滤数据,则可以使用表的Range
并致电SpecialCells
像这样的方法:
Dim table_range as Range
Dim filtered_range as Range
Set table_range = Range(...)
table_range.AutoFilter field:=... criteria1:=...
Set filtered_range = table_range.SpecialCells(xlCellTypeVisible)
这会返回一个Range
仅包含原始范围的可见单元格的对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)