Hi,
With the code below, I am trying to pass a range of cell values to an array. In this example, the range is specified as E2:E20. E2 will always be the starting cell, however the ending cell, E20 could be more or less, i.e., the cell range is variable. It would be best to take this into account, however, I don't know how to do that. The code that I tried is below:
I wanted to confirm that the array was properly passing values from my cell range into the array by viewing the Immediate Window so I added the Debug statement. When I run the code, I receive a 'subscript out of range' error.
Does anyone see why the error occurs and why I don't see the passed cell values in the Immediate Window?
Also, is there a way to modify the code so that the maximum range value can be variable?
Thanks,
Art
With the code below, I am trying to pass a range of cell values to an array. In this example, the range is specified as E2:E20. E2 will always be the starting cell, however the ending cell, E20 could be more or less, i.e., the cell range is variable. It would be best to take this into account, however, I don't know how to do that. The code that I tried is below:
Code:
Sub pass_range()
Dim i As Integer
Dim Ar As Variant
Ar = Sheets("Sheet1").Range("E2:E20").Value
For i = 2 To 20
Out = Ar(i)
Debug.Print Out
Next i
End Sub
I wanted to confirm that the array was properly passing values from my cell range into the array by viewing the Immediate Window so I added the Debug statement. When I run the code, I receive a 'subscript out of range' error.
Does anyone see why the error occurs and why I don't see the passed cell values in the Immediate Window?
Also, is there a way to modify the code so that the maximum range value can be variable?
Thanks,
Art