2

我有一个包含多列的表,我想使用条件过滤表并接收带有匹配项的范围。(1) 我知道我可以使用循环轻松地在表中进行迭代,或者 (2) 我可以在列中添加过滤器。

我不喜欢(1),因为表中的迭代太慢了,但我可以做到这一点。

Excel 是否有一个函数可以一步返回一个按特定条件过滤的范围?类似'function multipleVlookup(...) As Range'

编辑: 回答后我的代码:(感谢亚历山大)

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
4

1 回答 1

3

如果您可以过滤数据,则可以使用该表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仅包含原始范围的可见单元格的对象。

于 2012-08-23T23:08:14.800 回答