Setting a formula using VBA

  • Thread starter Thread starter Phill
  • Start date Start date
P

Phill

How do I set a cell to be a formula using VBA? I have
tried the following:
PNLWorksheet.Cells(lngDown, 9).Formula = "=" &
PNLWorksheet.Cells(lngDown, 8).Value & "/" &
PNLWorksheet.Cells(lngDenominator, 8)
 
Hi,
You can enter a formula in 2 ways :

1. a static formula
Cells(1,1).FormulaLocal = "=" & Cells(1,2) & "/" & Cells(1,3)

2. a dynamic formula
Cells(1,1).FormulaLocal = "=" & Cells(1,2).Address & "/" &
Cells(1,3).Address

I hope this helps
 
PNLWorksheet.Cells(lngDown, 9).Formula = "=" & _
"Sum(A1:A10)"

should work. If you want to express the formula in R1C1 terms

PNLWorksheet.Cells(lngDown, 9).FormulaR1C1 = "=" & _
"Sum(R1C1:R10C1)"

If you have a version other than English and want to use the same
terminology as would be used manually, then use

FormulaLocal
or
FormulaR1C1Local
 
Back
Top