I use a template Excel sheet with on the second row for some columns formulas.
I first fill in the columns with data from a db and then copy the formulas for the columns.
This works fine, except when the formula contains VLOOKUP, then the last argument (default value) is lost, resulting in an 'N/A'.
This is part of my C# code:
// Update formulas:
var columnsWithFormula = new[] { "H", "I", "K", "M", "Q", "R", "S", "T", "U", "V" };
foreach (var columnWithFormula in columnsWithFormula)
{
worksheet.Range[$"{columnWithFormula}{startRow}:{columnWithFormula}{row}"].Formula = worksheet.Range[$"{columnWithFormula}{startRow}"].Formula;
}
This formula works as expected:
=IF(AND(I8="N";Q8="J";R8="N");T8* K8; 0)
This one fails:
=IF(AND(Q8="J";R8="J"); MIN(T8*J8; VLOOKUP(T8; Informatie!$C$3:$D$10;2;0) ); 0)
Instead of pasting the exact formula, this is pasted:
=IF(AND(Q8="J";R8="J"); MIN(T8*J8; VLOOKUP(T8; Informatie!$C$3:$D$10;2) ); 0)
Notice the missing ;0 after ;2
Now my worksheet produces wrong values. When I manually change the formula in Excel all works fine.
What do I need to do to let xlsIO copy my formula without altering it?
Thanks,
Paul