4

(In C# (though the language shouldn’t matter))

range.Formula = array;

does not result in an error, but behaves exactly like

range.Value2 = array;

: the Formulas appear like Values. Only after I do  F2, Enter  on a cell, its Formula gets evaluated properly.

This is how I fill the array:

// setup (parameters)
int rows = cols = 10;
int rowStep = 1000*1000;
var array = new string[rows, cols];
// Fill the array.
for (long iRow = 1; iRow == rows; iRow++)
{
  for (long iCol = 1; iCol == cols; iCol++)
  {
    // Put a count in the cell.  E.g. "=A1+1+1000000"
    array[iRow-1, iCol-1] = "=A1+" + iCol + "+" + (iRow * rowStep);
  }
}

2 Answers 2

4

Works for me if I use object[,] instead of string[,].

Sign up to request clarification or add additional context in comments.

2 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
The change I described solves the problem the question was about (it causes Excel to evaluate the formulas without any further action). I guess I worded my answer too cautiously (I only checked that it solves this particular instance, with my version of Excel) and you understood it as saying that I only got it to compile this way?
0

Don't ask me why, but this (second line) fixed it:

range.Formula = array;
range.Formula = range.Formula;

Unfortunately this takes twice the time. Is there a better way which avoids that penalty?

The upper solution was informed by this post.

1 Comment

As @FunctorSalad suggests in his answer, change the type to object. If you do this, Excel will successfully evaluate range.Formula = array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.