Can you make a variable worksheet name?

ectoid

Board Regular
Joined
Jan 18, 2005
Messages
97
:oops:
This is driving me nuts...
Whether in VBA or Excel can you make a worksheet name a variable?

For example:
Set c=Sheets("=cell").Range(f6:f66)
where =cell is a variable cell reference.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
Do you want to change the worksheet name whenever you want in your code, or do you just want to read what it is currently? You can use ActiveSheet.Name. Something a little different might work better for what you're trying to do.
 

ectoid

Board Regular
Joined
Jan 18, 2005
Messages
97
Hey Taz,
Yeah, I'm trying to get the sheetnaming to be dynamic so that I can change where the name is coming from.
Does that make sense or no?
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Create a Public Const variable. Place it in a standar module (at the top). Then just refer to that variable when needed. This makes it so you only have to change the name once.

Example ...

<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Const</SPAN> SHEETNAME <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> = "SheetName"

<SPAN style="color:#00007F">Sub</SPAN> foo()
    MsgBox SHEETNAME
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 

Watch MrExcel Video

Forum statistics

Threads
1,130,048
Messages
5,639,769
Members
417,111
Latest member
buyukbang

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