2

I am creating an excel report in C#. When I add a formula like below, everything works fine:

totalCellFormulaRange.Formula = "=SUM(AH7:AS7)"; //totalCellFormulaRange is a Range object from Microsoft.Office.Interop.Excel

But now when I try to add a formula consisting of an if statement like below,

memberGuidesCellFormaulaRange.Formula = "=IF(LEFT(D7;12)=\"Welcome Pack\";O7*$AQ$4;0)";

then I get this error:

Exception from HRESULT: 0x800A03EC

The above if statement works 100% if typed out in a Excel sheet. It only fails in C# and the exception is thrown right when it hits this line of code.

Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
Tumelo
  • 301
  • 3
  • 18

1 Answers1

4

Although localization for excel allows for ";" use in place of commas, the COM interface doesn't register the ";" and a comma should be used instead.

memberGuidesCellFormaulaRange.Formula = "=IF(LEFT(D7,12)=\"Welcome Pack\",O7*$AQ$4,0)";

For more information about localization problems, and some general pointers when writing interop code for Excel, see this SO Q&A.

Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
Jay Wilson
  • 66
  • 5