1

コードから実行時エラー 9 (添字が範囲外) が発生する理由を理解するのに誰か助けてもらえますか?

  Dim prod(1 To 6) As String

  prod(1) = "001"
  prod(2) = "002"
  prod(3) = "003"
  prod(4) = "004"
  prod(5) = "005"
  prod(6) = "006"

  Dim sum(1 To 6) As Double
  For i = 1 to 6 Step 1
    sum(i) = 0
  Next i

  Dim sumA(1 To 12) As Double
  For i = 1 To 12 Step 1
    sumA(i) = 0
  Next i

  Sheets("Punching").Activate
  LR = Cells(Rows.Count, "G").End(xlUp).Row

  For i = 4 To LR Step 1
    For j = 1 To UBound(prod) Step 1
      If Cells(i, 11) = prod(j) Then
        sum(j) = sum(j) + Cells(i, 18).Value
      Else
        sum(j) = sum(j)
      End If
    Next j
  Next i

  For k = 4 To LR Step 1
    For l = 1 To UBound(sumA) Step 2
      **If Cells(k, 11) = prod(l) Then**
        sumA(l) = sumA(l) + Cells(k, 19).Value
        sumA(l + 1) = sumA(l + 1) + Cells(k, 20).Value
      Else
        sum(l) = sum(l)
      End If
    Next l
  Next k

エラー行は星印の行です。prodの配列を再利用できないからですか?なぜこのエラーが発生するのかわかりません。どんな助けでも大歓迎です!

4

0 に答える 0