运行时错误“6”:溢出 – 将数据保存到dynamic数组中

我是Excel-VBA的新手。 我的任务是计算网关的数量和网关的电路部分,然后将它们显示为可读的报告。 我的逻辑是首先计算网关的数量,然后使用do until循环来遍历数据的每一行。 检索电路部件名称,然后保存到每行调用“parts()”的数组中。

然而行“j = j + 1”抛出运行时错误'6':溢出。

任何人都可以帮我解决问题或给我一些build议?我感谢任何回应:)

Function countG450(index As Long, gateway As String, gatewayCount As Integer) Dim sheet As Worksheet Set sheet = ActiveSheet Dim row, rowCount As Range Set row = sheet.Rows(1) Dim thisRow As Long Dim parts() As String, partsCount As Integer Dim uniqueList() As Variant Dim vertical As String, horizontal As String Dim j As Integer Dim writeIndex As Integer index = 1 writeIndex = 1 RowIndex = 1 For i = 0 To gatewayCount j = 0 Do Until Application.CountA(sheet.Rows(RowIndex)) = 0 'save parts of gateway If (Left(Cells(RowIndex, 1), 4) = gateway) And Cells(RowIndex, 2) <> vbstringnull And Cells(RowIndex, 2) <> "ANALOG LINE" And Cells(RowIndex, 2) <> "DIGITAL LINE" Then ReDim Preserve parts(j) parts(j) = Cells(RowIndex, 2) **j = j + 1** End If 'Count the circuit parts of analog 'Count the circuit parts of digtal If (Left(Cells(RowIndex, 1), 4) <> gateway And Cells(RowIndex, 1) <> vbstringnull) Then uniqueList = GetUniqueValues(parts) 'Write parts of gateway Erase parts Erase uniqueList gateway = Left(Cells(RowIndex, 1), 4) RowIndex = RowIndex + 1 End If Loop Dim y As Variant y = DrawBorder(horizontal, vertical) Next End Function