【问题标题】:subscript out of range VBA code下标超出范围的 VBA 代码
【发布时间】: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 为这三个人做这件事。

标签: vba range out subscript


【解决方案1】:

查看this page 以获取有关此错误的信息。

在你的情况下,我会说这是第一个选项:

  • 您引用了一个不存在的数组元素。

检查 irj 的值是否不大于数组的维度... p>


要么:要么:

  • 您声明了一个数组,但没有指定元素的数量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多