For loop which returns a wrong array of elements

Viewed 97

I have a command button with a code like this:

Dim array1()
Dim nrow As Integer

nrow = Range("C4:C241").Count

ReDim array1(nrow)

For i = 0 To nrow
    'array1(i) = Range("C" & i + 3)
    array1(i) = i
Next

Range("AY4:AY" & nrow + 3) = array1

The comment symbols ' is present in the case you wanted to switch to make some experiments.

What I get running this macro in Excel is a column of values equal to 0, which is not what I would expect to get: I would like to print array1 in the Range("AY4:AY241").

Where am I wrong?

3 Answers
Related