2016-04-14 79 views
0

誰能幫我弄清楚爲什麼這個代碼錯誤是「下標超出範圍」。 (運行時錯誤9)下標超出範圍VBA代碼

Dim arrayU() As Variant 
Dim arrayX() As Variant 
Dim arrayW() As Variant 
Dim LrowU As Integer 
Dim LrowX As Integer 
Dim LrowW As Integer 
Dim i As Integer 
Dim j As Integer 
Dim bed_in_use As Integer 


    For i = 3 To LrowX 
    For r = 3 To LrowW 
    For j = 3 To LrowX 

    If bed_in_use >= 24 Then Exit For 

    If arrayX(i) = arrayW(r) Then 
    bed_in_use = bed_in_use - 1 
    If arrayX(i) = arrayU(j) Then 
    bed_in_use = bed_in_use + 1 

    Cells(i, "Y").Value = bed_in_use 
    End If 
    End If 
+2

這將取決於你的數組聲明。顯示宣言行。作爲'昏暗arrayx(...' –

+0

昏暗strDate 昏暗算作整數 昏暗arrayU()作爲變 昏暗arrayX()作爲變 昏暗arrayW()作爲變 昏暗LrowU作爲整數 昏暗LrowX作爲整數 Dim LrowW As Integer Dim i As Integer Dim j As Integer Dim bed_in_use As Integer – Zapata

+1

不在評論中,請將它放在原始文章中 –

回答

0

有關此錯誤的信息,請檢查this page

在你的情況我會說這是第一個選項:

  • 您引用不存在的數組元素。

檢查的i的值[RĴ並不比在那裏尺寸設計...


無論是或數組什麼大:

  • 您聲明瞭一個數組,但沒有指定元素的數量。