我有一个名为“销售跟踪器”的表格,我进行了自动过滤并获得了结果。现在我想将可见字段转移到我的数组 soArray 中,第一次浏览单元格时,它工作正常,我将需要的 4 个字段放入数组中,但是,第一次出现“运行时错误'9':下标超出范围”后,我做错了什么?任何帮助或推动都将不胜感激,谢谢以下是我的代码
Sub getAllSO()
Dim wkb As Workbook
Dim wks As Worksheet
Set wkb = Workbooks("ScrubCentral.xlsm")
Set wks = wkb.Sheets("Sales Tracker")
Dim tbl As ListObject
Set tbl = wks.ListObjects("SalesTracker")
tbl.AutoFilter.ShowAllData
tbl.Range.AutoFilter field:=4, Criteria1:=">0"
Dim soArray() As Variant
Dim rngVisible As Range
Dim i As Long
Dim rCell As Range
With wks
With .AutoFilter.Range
Set rngVisible = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
End With
For Each rCell In rngVisible
i = i + 1
ReDim Preserve soArray(1 To i, 1 To 4)
soArray(i, 1) = rCell(i, 2)
soArray(i, 2) = rCell(i, 3)
soArray(i, 3) = rCell(i, 4)
soArray(i, 4) = rCell(i, 13)
Debug.Print soArray(i, 1), soArray(i, 2), soArray(i, 3), soArray(i, 4)
Next rCell
End With
End Sub