vba use cell value to select sheet within formula

twday

New Member
Joined
Sep 16, 2014
Messages
3
Is there a way I can us strName in place of 'X009516'! so that I can have the macro pull from a user designated (entered into M5) sheet?

Code:
Dim strName As String
strName = Range("M5")
    
    Range("B1").Select
    Selection.End(xlDown).Offset(1).Select
    ActiveCell.Formula = "='X009516'!B1"
    Selection.Offset(0, 1).Select
    ActiveCell.Formula = "='X009516'!C9"
    Selection.Offset(0, 1).Select

Thanks in advance for any advice!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,455
Try this...

ActiveCell.Formula = "='" & strName & "'!C9"



Alternatively, you could put this formula in cell B1
=INDIRECT("'"&M5&"'!B1")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,190,914
Messages
5,983,540
Members
439,848
Latest member
timmyo

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