Vba 运行时错误“9”下标超出范围
我有个大问题。我有一个宏从上周开始就没有运行,我不知道为什么?我总是得到错误:运行时错误9 我知道重命名或数组一定有问题,但我什么也没找到。 请你检查一下这个代码,也许你能找到问题所在 提前谢谢! 你好,克里斯汀 这只是宏观经济的一部分。 当k=10时,错误在第8行 Ubound理论上是9 EditRowk=EditRowk+insdels*k-1Vba 运行时错误“9”下标超出范围,vba,range,subscript,Vba,Range,Subscript,我有个大问题。我有一个宏从上周开始就没有运行,我不知道为什么?我总是得到错误:运行时错误9 我知道重命名或数组一定有问题,但我什么也没找到。 请你检查一下这个代码,也许你能找到问题所在 提前谢谢! 你好,克里斯汀 这只是宏观经济的一部分。 当k=10时,错误在第8行 Ubound理论上是9 EditRowk=EditRowk+insdels*k-1 'Populate input sheet insdels = 0 For i = 1 To UBound(EditRow) If FAT_Bl
'Populate input sheet
insdels = 0
For i = 1 To UBound(EditRow)
If FAT_Blocks(i).Range_Name <> "Absent_from_BCM" Then ' only process the blocks that were present
k = FAT_Blocks(i).GPI_Block_Number 'ERROR***************************************************************************
EditRow(k) = EditRow(k) + (insdels * (k - 1))
For m = 1 To FAT_Blocks(i).Rows
If FAT_Blocks(i).Data(m, 1) <> 0 Then ' ignore rows with zero cost/revenue in year 1
If GPIsheet.Cells(EditRow(k), 2).Interior.ColorIndex <> new_CI Then
new_InsDel (1)
insdels = insdels + 1
EditRow(k) = EditRow(k) + (k - 1)
End If
If FAT_Blocks(i).Row_Title(m) Like "*One Time*" Then
y = 0
ElseIf FAT_Blocks(i).Row_Title(m) Like "*Recurring*" Then
y = 1
Else
y = 2
End If
With GPIsheet
.Range("Original_Import_Data").Offset(EditRow(k) - 1, 0).ClearContents ' clear any mung before updating
' fill the "new_CI" coloured cells on the left
.Cells(EditRow(k), 2).value = BCMid & " " & FAT_Blocks(i).Row_Title(m) ' row description
.Cells(EditRow(k), 3).value = FAT_Blocks(i).Data(m, 1) ' unit value
.Cells(EditRow(k), 4).value = change_pc(y) ' change %
.Cells(EditRow(k), 5).value = change_year(y) ' change year
.Cells(EditRow(k), 6).value = vol_driver(y) ' volume driver
' fill the grey stuff on the right
With .Range("Original_Import_Data").Offset(EditRow(k) - 1, 0)
.Cells(1, 1) = yr ' Contract length
.Cells(1, 2) = BCMid ' BCM unique id
For j = 1 To yr
.Cells(1, 2 + j) = FAT_Blocks(i).Data(m, j) ' data for corresponding year
Next
End With
End With
EditRow(k) = EditRow(k) + 1
End If
Next m
End If
Next i
在i和k上使用debug.print,查看其中一个是否超出范围/数组上限?感谢Alex的快速回答,我将在周一工作时检查。