for循环不迭代整个循环

时间:2015-11-22 23:01:26

标签: excel-vba for-loop vba excel

在Excel VBA中,我有2个循环 - i循环和j循环。当程序进入j循环时,循环应该运行9次,因为i = 9。但是j循环只运行一次。

Public Sub ArrayReader(ByRef internalArray() As String, ByRef s As String)

Dim j As Integer
Dim str1 As String

For i = LBound(internalArray) To UBound(internalArray)
  If internalArray(i) = "(" Then
   MsgBox "check" & i
    For j = 0 To j = i
     str1 = str1 & internalArray(j)
     MsgBox "j loop is running. Iteration#:" & j
    Next j
   MsgBox str1 & "J value is:" & j
   MsgBox "I value is:" & i
  End If
Next i

End Sub

1 个答案:

答案 0 :(得分:1)

你真的很亲密。您只需将循环语句更改为For j = 0 To i而不是For j = 0 To j = i