【发布时间】:2016-04-14 23:26:39
【问题描述】:
谁能帮我弄清楚为什么这个代码错误是“下标超出范围”。 (运行时错误9)
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
【问题讨论】:
-
这取决于您对数组的声明。显示声明行。如
Dim arrayx(... -
Dim strDate Dim Count As Integer 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
-
请不要在cmets中,请放在原帖中。
-
你需要设置数组的大小。就在您的循环之前,您需要对所有三个执行此操作。
ReDim ArrayX(3 to Lrowx) as Variant为这三个人做这件事。