Returns or sets the cell's formula. Read/write Variant.
If the cell contains a constant, this property returns the constant.
If the cell contains a formula, the Formula property returns the formula as a string (including the equal sign).
If the range is a one- or two-dimensional range, you can set the formula to a Variant Array of the same dimensions.
Similarly, the formula property returns the Variant Array.
Setting the formula for a multiple-cell range fills all cells in the range with the formula.
NativeExcel's formula compiler use the semicolon sign instead of comma as the function argument separator.
This example sets the formula of cell A2 and obtains the result of formula into Val variable.
With Workbook.Sheets[1] do begin
Cells[1,1].Value := 100;
Cells[2,1].Formula := '=IF(A1>70;A1/2;A1)';
Val := Cells[2,1].Value; //Val = 50
end;
This example copies the formulas from A1:F1 range to A2:F2 range.
With Workbook.Sheets[1] do begin
Range['A2', 'F2'].Formula := Range['A1', 'F1'].Formula;
end;
This example is the same to previous.
With Workbook.Sheets[1].Range['A1', 'F1'] do
Offset[1,0].Formula := Formula;