What are shared formulas? How do I create them?
Excel 2007 has a neat feature which saves a lot of coding when it comes to applying the same formula to a range of cells. A formula in one cell can be marked as
and all cells referenced by the shared formula obtain their own version of the formula. So if cell
has the formula D5*12
, then cell
would have the formula
etc. etc. To set up a shared formula simply call the CreateSharedFormula method. In the following example, the formula in cell
is marked as shared
and all the other cells in the range
are assigned their own variation of the formula.
worksheet.CreateSharedFormula(worksheet.Cell(5, 5), worksheet.Cell(21, 5));