ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting a formula using VBA (https://www.excelbanter.com/excel-programming/289320-setting-formula-using-vba.html)

Phill

Setting a formula using VBA
 
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)


Chris Hoffman

Setting a formula using VBA
 
Phill,
Try this: .FormulaR1C1 = "the formula you want"

HTH
Chris Hoffman

"Phill" wrote in message
...
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)




tolgag[_38_]

Setting a formula using VBA
 
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


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

Setting a formula using VBA
 
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



--
Regards,
Tom Ogilvy


Phill wrote in message
...
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)





All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com