vba 把for循环中的值,传出循环体外
Dim i1 As Integer
Dim i4 As String
i4 = 1234
Dim i2 As Integer
i2 = 1
Dim arr1() As Integer
ReDim arr1(1 To 10) As Integer
For i1 = 1 To 10 Step 1
If Sheet1.Cells(i1, 2) = "" And Sheet1.Cells(i1, 3) = i4 Then
arr1(i2) = Sheet1.Cells(i1, 1).Row
i2 = i2 + 1
End If
Next
MsgBox (i2)
我的想法是要把sheet1中符合条件的单元格的值,赋值到数组arr1。我用变量i2存储数组arr1的下标,但是为什么for循环结束后,变量i2的值一直是1