Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

CodeName reference

I need to reference the code name of  a sheet instead of the name.

Right now I am using
Set Mysheet = mybook.sheets("ABD")

How do I change to reference Sheet1 which is the code name and use in a range?
0
leezac
Asked:
leezac
1 Solution
 
NorieCommented:
What is mybook?

How do you want to use the codename?

Where is the code located?
0
 
leezacAuthor Commented:
mybook = application.activeworkbook

code is located in a module

The name of the sheet is going to change every month so I need to be able to code using the code name because the sheet name will change.

To be able to select range starting at B5 on Sheet1 using codename not tab name.

__________________________________________________________

or something like this, but be able to use code name not "Data"

Set ActWks = ActiveSheet

Sheets("Data").Select

ActWks.Select


I have not created code yet, but trying to figure out name part first.
0
 
NorieCommented:
if the code is in the same workbook as the sheet you want to refer to then you can just use this.
Set Mysheet = Sheet1

Open in new window


You can then use Mysheet just as you normally would.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
byundtCommented:
You might use code like this:
Dim wsData As Worksheet
Set wsData = Sheet1        'or perhaps ActiveWorkbook.Sheet1

Open in new window


The worksheet codename is good to use when the user might change the name of the worksheet, but the same worksheet will be present in the workbook at both design time (when you write the code) and run time (when the user runs the macro).

Based on your description ("the name of the sheet is going to change every month"), I am guessing that a new worksheet is being created or is being imported.  If so, you won't be able to count on the worksheet having the same codename every month.

As an alternative, if the worksheet is always in the same position (first sheet, second sheet, etc.) in the workbook, then you can identify it that way.
Dim wsData As Worksheet
Set wsData = ActiveWorkbook.Worksheets(1)            'First worksheet in workbook

Open in new window

0
 
yuppyduCommented:
When you say that the name of the sheet changes, are you referring to the name appearing in the tab at the bottom?
0
 
Rob HensonIT & Database AssistantCommented:
How about creating a named range in a cell on that sheet, eg "DATA_TAB"

Then use:

Application.Goto Reference:="DATA_TAB"

As the Sheet name changes so will the reference for named range but macro doesn't need to change.

Thanks
Rob H
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now