refer to a sheet in a macro

ultratch47

Board Regular
Joined
Aug 6, 2002
Messages
126
here is macro:
Range("C12").Select
ActiveCell.FormulaR1C1 = "=Sheet1!R[-11]C[3]"
Range("D12").Select
ActiveCell.FormulaR1C1 = "=(Sheet3)!R[-11]C[2]"
Range("B14").Select
ActiveCell.FormulaR1C1 = "=Sheet1!R[-13]C[6]"
Range("B15").Select
ActiveCell.FormulaR1C1 = "=Sheet1!R[-14]C[7]"

the sheet3 in parenthesis will not compute,i would like to reference the 3rd sheet in the workbook, (the name of this sheet will never be the same)
how should htis be written correctly to refer to Sheet3?

here are my sheet names:
Sheet1 (sheet1)
Sheet2 (sheet2)
Sheet3 (test)

thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try --

Dim ThirdSheet as String
ThirdSheet = Sheets(3).Name

...

ActiveCell.FormulaR1C1 = "=" & ThirdSheet & "!R[-13]C[6]"

Untested...
 
Upvote 0
Andrew, i got the same error, not sure why

Jon, yours works but i got this as the final formula in the cell:
=test!J65535
i need it to equal:
=test!F1

it may be because i dont understand that line ("!R[-11]C[2]"a) as to why i cant figure it out.. sorry for the ignorance.
thanks
 
Upvote 0
It worked when I tested it.

To get the code for the last bit turn on the macro recorder and enter the formula manually. Make sure you use proper relative and absolute references. Turn off the recorder an look at the code.

Or you could use the Formula property:

ActiveCell.Formula = "=" & Sheet3.Name & "!F1"
 
Upvote 0

Forum statistics

Threads
1,203,219
Messages
6,054,216
Members
444,711
Latest member
Stupid Idiot

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