Cell value as sheet name

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
775
Office Version
  1. 365
Platform
  1. Windows
The value in cell C3 of the Mockup sheet is 1. For the simple code below, I'd like to know how to change the "1" in red (the sheet name) so that the value comes from C3 from the Mockup sheet. (Something like Sheets(Sheets("Mockup").Range("C3").Value).Select ​???)

Rich (BB code):
Sub Cabin()


    Sheets("1").Select
    Range("A4").Select


End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You almost have it, this is a wierd little quirk of VBA.

Sheets are also Indexed...Numbered from 1 to xx (however many sheets you have)
So if you just happen to have a sheet named 1 (you right clicked the tab, and typed in 1 as it' name)
That is not necessarliy the same as the sheet with the index number 1.

Sheets(1) - this refers to the first sheet in the book
Sheets("1") - this refers to the sheet named "1"
They are not necessarily the same sheet.

The line you tried
Sheets(Sheets("Mockup").Range("C3").Value).Select
This would work with any non numeric sheetname, like "Sheet2"
But Sheets("Mockup").Range("C3").Value is being returned as a NUMBER, so you're getting the reference like
Sheets(1), but you want Sheets("1")

Try changing .Value to .Text
 
Upvote 0
Works perfectly with that change to .Text

Thanks so much for the explanation. My sheet names intentionally are numbers, and I did not realize the implications of using them. Appreciate your help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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