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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

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!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,025
Messages
5,856,912
Members
431,837
Latest member
megantang

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