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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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.
 
Upvote 0
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?
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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