21.1
20.2
20.1
19.2
19.1
18.2
18.1
17.2
A newer version of this page is available. Switch to the current version.

# How to: Add Formulas to Cells

• 2 minutes to read

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 equals sign (“=”).

This example demonstrates how to create a simple formula using constants and calculation operators, and add this formula to a cell. Constants are values that are not calculated (e.g., date values, numbers, text strings). Operators specify what calculations should be performed on a formula’s elements.

##### NOTE

A complete sample project is available at https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-e4655

``````// Use constants and calculation operators in a formula.
workbook.Worksheets.Cells["B2"].Formula = "= (1+5)*6";
``````

For more information on formulas, refer to the Spreadsheet Formulas section, and review the following examples.

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 the need to copy the same formula to multiple cells and manually update 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.

See Also