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?
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

earlyd

Well-known Member
Joined
Dec 10, 2002
Messages
1,199
make sure the value in B48 is numeric. Didn't know NO could be used for a variable - would have thought it was reserved?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

cdhoughton

Board Regular
Joined
Dec 5, 2003
Messages
170
Cheers folks, turned out it was the R1C1 that was the problem!

Thanks for your help!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,329
Members
414,055
Latest member
mcarduner

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
Top