PDA

View Full Version : Formula VBA Help



gimli
04-27-2010, 11:54 AM
Hey again,

Instead of putting a formula in a cell I am trying to put it in the sheet module like this


Range("C18").Formula = "ROUND(0.97*$F$13,3))"


It doesnt seem to work. That should act just like it was a formula typed into a cell right?

Do I have the syntax right?

Thanks much

Bob Phillips
04-27-2010, 12:22 PM
Range("C18").Formula = "=ROUND(0.97*$F$13,3))"

gimli
04-28-2010, 03:54 AM
XID,

I used your posted forumula and it doesnt populate the cell. I have it on the worksheet module right? Do I need some other code to make it work?

thanks

p45cal
04-28-2010, 04:38 AM
XID,

I used your posted forumula and it doesnt populate the cell. I have it on the worksheet module right? Do I need some other code to make it work?

thanks

It doesn't matter too much, but it does matter that there's an extra closing parentheses at the end of the formula.

gimli
04-28-2010, 04:54 AM
I tried that also...doesnt populate C18 with a value


Range("C18").Formula = "=ROUND(0.97*$F$13,3)"

p45cal
04-28-2010, 05:46 AM
what does it populate with?

Perhaps you need to execute it.
run this macro:
Sub blah()
Range("C18").Formula = "=ROUND(0.97*$F$13,3)"
End Sub

gimli
04-28-2010, 05:57 AM
This dosent poulate anything.


Range("C18").Formula = "=ROUND(0.97*$F$13,3)"


this works when I run the sub



Sub blah()
Range("C18").Formula = "=ROUND(0.97*$F$13,3)"
End Sub


Here is my confusion..Keep in mind Im a newbie...

Shouldnt just putting this in my sheet module populate cell C18?



Range("C18").Formula = "=ROUND(0.97*$F$13,3)"


Why do I need to run a sub to do it?

p45cal
04-28-2010, 06:16 AM
'coz that's the way it is. Code needs to be executed.
You can arrange for the sub to be run in various ways; a click of a button, the opening of the workbook, activating the worksheet, being called from another sub... etc. but you need to set that up.

Eg.:
If you put a shape on the sheet, you can right-click it and choose Assign macro, and then choose the sub you've just written. Thereafter clicking the shape will execute the sub.

gimli
04-28-2010, 06:20 AM
Ahhh ok..now I got it. So I could make a sub with a bunch of formulas and the activate it when the workbook opens. Got it

thanks for helping the brain dead