... Why I need cells.formula when I can do it without cells.formula ...
Hi
Why I need cells.formula when I can do it without cells.formula as following:
Thank you so much.Code:Sub cell_formula() Workbooks(1).Worksheets(1).Cells(1, 1).Value = "=sum(c1+c2)" End Sub
Workbooks(1).Worksheets(1).Cells(1, 1).Formula = "=sum(c1+c2)"
Workbooks(1).Worksheets(1).Cells(1, 1).Value = "=sum(c1+c2)"
'Or
Workbooks(1).Worksheets(1).Cells(1, 1) = "=sum(c1+c2)" 'The default property of range is value
Range("A1").FormulaR1C1 = "=sum(c1+c2)" 'Excel could interpret different
Excel 2010 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | 910.63 | |||||
2 | 125.65 | |||||
3 | 784.98 | |||||
Sheet3 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D1 | =SUM(C2:C3) |
Sub TestFormVal()
Debug.Print Range("D1").Value
Debug.Print Range("D1").Formula
End Sub
I think that is what pgc was saying... if you want to read (back) the formula that is in the cell, you need to use the Format property to get the text representation of the formula.Can you clarify, pgc? This does exactly what I'd expect
Code:With Range("A2") .Value = "=sum(b2,c2)" [B][COLOR="#FF0000"]Debug.Print .Formula[/COLOR][/B] End With