2

To load formulas in a range I've used this method

ws1.Cells["B4:D4"].LoadFromText($"={con_Fu_LF},={con_Un_LF},={con_Fo_LF}");

and to evaluate I've called

ws1.Cells["B4:D4"].Calculate();

Opening the workbook I see strings in that range, for example in B4:

='Fu-LF'!F6841+'Fu-LF'!K6841

these are evaluated when I click on formula bar selecting a cell and press enter.

I want these to be evaluated automatically, how to do?

1 Answers1

0

LoadFromText sets the cell .Value property. But you need to set the .Formula like this:

ws.Cells["B4"].Formula = $"={con_Fu_LF}";

It works with the spacebar trick because that is Excel itself detecting that it "looks" like a formula and automatically setting it.

There is no way to do it that doesnt require you to loop through the cells/strings manually.

Ernie S
  • 13,902
  • 4
  • 52
  • 79
  • Is there any way to set formulas for a range? For example: `ws1.Cells["B4:D4"].Formula = $"={con_Fu_LF},={con_Un_LF},={con_Fo_LF}";` –  Nov 29 '17 at 07:44
  • @Emon no, unfortunately, I have never seen a way. In theory the logic would be the same as `LoadFromText` so could put in a gut hub request or folk the repo and try it. – Ernie S Nov 29 '17 at 11:26