This is the exception I'm getting:
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Range.set_Formula(Object value)
My code looks like this:
Range rng = activeWorksheet.get_Range("A1");
rng.Formula = "=SUM(A4*C4;A5*C5;A6*C6;A7*C7)/SUM(A4:A7)";
Whenever I run this code I get the previously mentioned exception. However, when I run this code:
Range rng = activeWorksheet.get_Range("A1");
rng.Formula = "=SUM(A4:A7)/4"
This works perfectly. No exception.
I've checked both formulas, they work perfectly fine in my Excel. I've tried setting:
Application.Calculation = XlCalculation.xlCalculationAutomatic;
This does not help at all, I've been googling this solution and have not found anything useful. Does anyone have a clue what might be wrong?