Macro to refer to cell containing sheet name in W2

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the sheet name in Cell W1 using the formula

Code:
 =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)

I have a formula in W2 to put the sheet name in quotation marks

=""""&W1&"""" resulting in "Forms outstanding"

I would like to amend my macro code below to refere to cell W2 instead of having to type on the sheet name

Code:
Sheets("Forms Outstanding").Copy

It would be appreciated if someone could kindly amend this code
 

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
The quotes are not necessary, you can directly use the result you have in cell W1, try:

VBA Code:
Sub copysheet()
  Sheets(Range("W1").Text).Copy
End Sub
 
Upvote 0
Solution
Thanks Dante. This works perfectly

I tried using this on code below, but get "subscript out of range"

Code:
Sheets(Range("W1").Text).Activate

If I use code below it works

Sheets("Forms outstanding").Activate

Kindly amend to refer to Cell W1
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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