Arrays Can';t将自动筛选的范围值转换为数组-仅第一个值

Arrays Can';t将自动筛选的范围值转换为数组-仅第一个值,arrays,excel,vba,range,autofilter,Arrays,Excel,Vba,Range,Autofilter,仅返回已过滤单元格的返回列表的第一个值。如果我不使用过滤的单元格,则可以使用其他方式: Dim tmp, tmpfilter As Variant ' returns the list of cell values tmp = teamRosterSheet.Range("D2", teamRosterSheet.Range("D2").End(xlDown)).Value ' returns 3 Debug.Print teamRosterSheet.Range("D2", teamRos

仅返回已过滤单元格的返回列表的第一个值。如果我不使用过滤的单元格,则可以使用其他方式:

Dim tmp, tmpfilter As Variant

' returns the list of cell values
tmp = teamRosterSheet.Range("D2", teamRosterSheet.Range("D2").End(xlDown)).Value

' returns 3
Debug.Print teamRosterSheet.Range("D2", teamRosterSheet.Range("D2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible).Count    

' but only returns the first cell value and not all three other cells in my example (filtering is working ok as I can see the 3 non-contiguous rows only been shown)
tmpfilter = teamRosterSheet.Range("D2", teamRosterSheet.Range("D2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible).Value

我做错了什么?

一个很好的问题!当您将自动筛选列捕获到VBA数组中时,必须循环特殊单元格。例如:


我本希望摆脱一个循环来填充阵列,但唉,我会忍受的。谢谢
Sub GrabData()
    Dim rGrab As Range, ary()
    Set rGrab = Range("B2:B13").Cells.SpecialCells(xlCellTypeVisible)
    ReDim ary(1 To rGrab.Count)
    i = 1
    For Each r In rGrab
        ary(i) = r.Value
        i = i+1
    Next r
End Sub