我从未擅长开发数组。我试图在电子表格中循环遍历大量数据,将其存储在数组中,并使用它基本上通过VLOOKUP
语句执行If
函数。当我运行程序时,我得到:
运行时错误9 - 下标超出范围(记下错误在哪里)
编辑:当我评论Redim
语句时,我在j&#34上输入错误;输入错误" ...数据只保留整数....
Dim LoArray()
Dim TargetWorkbook As Workbook
Dim SourceWorkbook As Workbook
Dim i As Long
Dim j As Long
Dim k As Long
Assign the Workbook File Name along with its Path
TargetPath = "C:\filepath.....xlsx"
Set TargetWorkbook = Workbooks.Open(TargetPath)
Set SourceWorkbook = ThisWorkbook
'Sets Counter in For Loop
k = TargetWorkbook.Sheets("LRG Pivots").Cells(Rows.Count, "A").End(xlUp).row
'error happens here
ReDim LoArray(1 To i, 0 To 1)
'Count Rows in LoadWTable
For row = 6 To k
i = i + 1
j = Cells(row, 2) 'throws mismatch error
LoArray(i, j) = Cells(i, j)
Next row
'Store Rows in Array
ReDim Preserve LoArray(1 To i, 0 To 1)
End Sub