using predefined constants in excel formula

keeper85

New Member
Joined
Jun 10, 2011
Messages
15
have the following code, which works properly:




HTML:
Sub hey() 
 
With Workbooks(PosBook).Worksheets(PosSheet) 
.Range("h5:h" & uff2).FormulaR1C1 = "='[Clearing position per entity (3).xls]Report1'!R[-1]C40" 
 
End With 
 
End Sub




</PRE>
However, I want to use predefined constants to refer to the book and the sheet, instead of the actual names. So I want something like this, but it does not work (for simplicity some of my code is not included here).




HTML:
Public Const ReportBook As String = "Clearing Position per entity (3)" 
Public Const ReportSheet As String = "Report1" 
Sub hey() 
 
With Workbooks(PosBook).Worksheets(PosSheet) 
.Range("h5:h" & uff2).FormulaR1C1 = _ "='[Reportbook]ReportSheet'!R[-1]C40" 
 
End With 
 
End Sub




</PRE>
So I want to use predefined references, instead of the actual book and sheet names. This code of course does not work. Can someone help me in making this code correct? Thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
something like

Code:
.Range("h5:h" & uff2).FormulaR1C1 = _ "='[" & Reportbook & "]" & ReportSheet & "'!R[-1]C40"
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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