Referencing cells from other workbooks

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I know it's possible to access tabs/cells from other closed workbooks by using a formula.

Rich (BB code):
Range("A1").Formula = "=[Book2]Sheet1!$A$1"

However, is it possible to use that formula by using the worksheet number of the closed workbook, rather than the tab name?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Well, this code would work, but you would need to temporarily open the other workbook to use it (that shouldn't be an issue, you should be able to open and close that workbook in the VBA code).

It uses the sheet index numbers to "capture" the sheet name of the sheet you want.

Code:
    Dim mySheetName As String
 
'   Goto source workbook
    Windows("Book1.xls").Activate
    
'   Goto specified sheet and capture the name
    mySheetName = Sheets(1).Name
    
'   Goto destination workbook and enter formula
    Windows("Book2.xls").Activate
    Range("A1").Formula = "=[Book1]" & mySheetName & "!$A$1"
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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