I am trying to use a multidimensional array of strings to fill an excel sheet and have run into trouble when inserting formulas. The following small case illustrates the problem:
Dim tA(3, 3) As String
tA(1, 1) = "=HYPERLINK(""www.stackoverflow.com"")"
tA(1, 2) = "=HYPERLINK(""www.stackexchange.com"")"
tA(2, 1) = "=2+5"
tA(2, 2) = "Normal Text"
worksheet.Range(worksheet.Cells(1, 1), worksheet.Cells(4, 4)).Value = tA
When this code is evaluated, the excel sheet does not automatically convert the hyperlinks or evaluate the formulas. That is, when I look at Excel, the cell at (2,1) will display “=2+5” instead of “7” as desired. Is there a way to force excel to evaluate all cells to see if a command is present?
I should note that if I insert a command into an individual cell then it is evaluated properly, but that isn’t an option as I have many thousands of cells and filling them one at a time is several orders of magnitude slower.
You get that because the formulas get transferred as values, add the following line to your code and you should be good to go:
worksheet.Range(worksheet.Cells(1, 1), worksheet.Cells(4, 4)).formular1c1= worksheet.Range(worksheet.Cells(1, 1), worksheet.Cells(4, 4)).formular1c1full code would be