使用for循环遍历2D数组

我正在试图在一张表格上创build一个关联表格,这个表格从另一张表格中提取数据。 通过关联我的意思是,如果源数据表中的数据发生更改,则会反映在新表中。 我也希望只有新的表格才具有一定的独特价值。 在我的情况下,我想提取有关零件编号的信息。 原始的源数据将有许多行包含相同的部件号,但我只关心显示其中之一。

到目前为止,这是我所拥有的:

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean Dim bDimen As Byte, i As Long On Error Resume Next If IsError(UBound(arr, 2)) Then bDimen = 1 Else bDimen = 2 On Error GoTo 0 Select Case bDimen Case 1 On Error Resume Next IsInArray = Application.Match(stringToBeFound, arr, 0) On Error GoTo 0 Case 2 For i = 1 To UBound(arr, 2) On Error Resume Next IsInArray = Application.Match(stringToBeFound, Application.index(arr, , i), 0) On Error GoTo 0 If IsInArray = True Then Exit For Next End Select End Function Sub Part_Separator() Dim Source As Worksheet Set Source = Sheets("Part Tracking Scorecard") Dim ref1(), ref2() As Variant Dim row, index, lastrow, lastcolumn As Integer row = 92 lastrow = 866 lastcolumn = 84 ref1 = Source.Range(Source.Cells(row, 1), Source.Cells(lastrow, lastcolumn)) ReDim ref2(UBound(ref1, 1), UBound(ref1, 2)) For index = 0 To (lastrow - row) If IsInArray(ref1(index, 6).Value, ref2) Then index = index + 1 Else ref2(index) = ref1(index) 'copy the entire row from source to ref2 index = index + 1 End If Next index Dim NewFile As Worksheet Set NewFile = Sheets("Unique Parts") Dim ref2dimension_x, ref2dimension_y As Integer 'find dimensions of ref2 array ref2dimension_x = UBound(ref2, 1) - LBound(ref2, 1) + 1 ref2dimension_y = UBound(ref2, 2) - LBound(ref2, 2) + 1 For index = 2 To ref2dimension_x 'go through entire new sheet and set values For index2 = 1 To ref2dimension_y NewFile.Cells(index, index2).Value = ref2(index - 1, index2) Next index2 Next index Erase ref1() Erase ref2() 'free up the space occupied by these arrays End Sub 

我的问题,当我运行这个,我得到一个错误,在第一个循环,我试图迭代通过我的ref1数组,这是我的所有源数据的数组。 错误说我的下标超出范围。 这个循环假设检查特定值是否在我的ref2数组中是唯一的。 如果find特定值,则转到下一行,如果不添加与我正在检查的值相关的值的行。