运行时错误“9”下标超出范围

时间:2015-01-23 15:22:41

标签: vba range subscript

我有一个很大的问题。我有一个自上周以来没有运行的宏,我不知道为什么?我总是得到错误:"运行时错误9 ...."

我知道重命名或数组一定有问题,但我找不到任何东西。 你可以检查一下这段代码,也许你可以找到问题。

提前致谢! 此致,克里斯蒂安

它只是大宏的一部分。 " k"错误发生在第8行。将=" 10"

Ubound是teoretically" 9" (??)

EditRow(k)= EditRow(k)+(insdels *(k - 1))

'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

0 个答案:

没有答案