VBA Formula issue

EB08

Active Member
Joined
Jun 9, 2008
Messages
343
In short, I need to enter a formula into a variable cell via VBA. I have done similar things to this but for some reason, can't get this one to work. one of the cells in the formula itself also come from a variable. Any help is appreciated!

My most recent attempt is:

Cells(52, startcolumn).Formula = "=(" & Cells(50, startcolumn) & "/e50)-1"

startcolumn already has the value of 11 in this example.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
What value is actually in Cells(50, startcolumn)?

If it's empty the formula will end up as =(/e50)-1, which isn't a valid formula.
 
Upvote 0
Completely dropped the ball on that one! I had an empty cell currently in place. On another note, I havent decided which way would be best yet but would i be able to use the cell reference in the formula so it wouldn't hard code the value (referring to cells(50,startcolumn))? so in this case, i would like the formula to possibly be entered as =(k50/e50)-1 instead of (value of k50 hardcoded/e50)-1. Thanks again.
 
Upvote 0
Just add address.
Code:
Cells(52, startcolumn).Formula = "=(" & Cells(50, startcolumn).Address & "/e50)-1"
Note the default return for Address is absolute. eg $K$50.:)

There are however arguments you can use to change it to use relative referencing.
 
Upvote 0
Great...Thank you, this was a lagging piece of something I was building, now it's fixed!
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top