Index function within a For-Next loop

  • Hi,


    I have a For-Next loop which contains an index function. For the 'row' variable, I would like to use 'x+1', but it doesn't seem to like this. The index function is taking a name from the 'SizeNames' table and putting it in another table. I need to use the loop because the 'number of sizes' can vary and both the position of the SizeNames table and the destination table may vary.


    Code
    For x = 0 To NumberofSizes - 1
        Range(CellsCornerCell).Offset(1, 5 + (x * NumberofMinerals)) _
        .FormulaArray = "=index(Configuration!SizeNames, x+1, 1)"
    Next x


    Many thanks.

  • Re: Index function within a For-Next loop


    If you want to include x in the formula you could try something like this.

    Code
    For x = 0 To NumberofSizes - 1 
        Range(CellsCornerCell).Offset(1, 5 + (x * NumberofMinerals)) _ 
        .FormulaArray = "=index(Configuration!SizeNames, " & x+1 & ", 1)" 
    Next x


    By the way are you sure that's an array formula?

    Boo!:yikes:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!