How to: Add Formulas to Cells
To add a formula to a cell, use the Range.Formula property of the Cell object. Assign the required formula to this property as a string starting with the "=" sign. For more information on formulas, refer to the Spreadsheet Formulas section, and review the following examples.
- How to: Use Constants and Calculation Operators in Formulas
- How to: Use Cell and Worksheet References in Formulas
- How to: Use Names in Formulas
- How to: Use Functions and Nested Functions in Formulas
When you set the Range.Formula property for the cell range, each cell in this range will contain the specified formula with adjusted cell references (all relative cell references included in the formula will automatically be changed). This approach allows you to avoid duplicating the same formula for multiple cells and manually updating cell references. Refer to the How to: Create Shared Formulas example for more information.
To perform calculations with arrays of cells, use array formulas. To create an array formula, call the Range.ArrayFormula method. Refer to the How to: Create Array Formulas example for more information.