Cell value as sheet name

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
762
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

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