Variable cell in formula

cdhoughton

Board Regular
Joined
Dec 5, 2003
Messages
170
I have a VB script that adds a FormulaR1C1 value to a cell.

However, I need to set a part of the formula to a different value in another cell:
----------------------
No = Sheets("Management Information").Range("B48").Value + 7

Sheets("Sheet1").Range("A1").FormulaR1C1 = "=-INDIRECT(""'""&SheetName&""!$C$" & No & """)"
----------------------

At the moment the value is coming out at 7 and not recognising the first bit of the formula?!?

Any ideas?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
make sure the value in B48 is numeric. Didn't know NO could be used for a variable - would have thought it was reserved?
 
Upvote 0
Your code gave me a #NAME error. Is this what you want?

Code:
Sheets("Sheet1").Range("A1").Formula = "=-INDIRECT('" & SheetName & "'!$C$" & No & ")"

When using A1 style references you should use the Formula property, not the FormulaR1C1 property.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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