Solved

CodeName reference

Posted on 2013-12-10
6
168 Views
Last Modified: 2013-12-13
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
Comment
Question by:leezac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 39710094
What is mybook?

How do you want to use the codename?

Where is the code located?
0
 

Author Comment

by:leezac
ID: 39710105
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
 
LVL 34

Expert Comment

by:Norie
ID: 39710135
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
Technology Partners: 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!

 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39710411
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
 
LVL 4

Expert Comment

by:yuppydu
ID: 39710701
When you say that the name of the sheet changes, are you referring to the name appearing in the tab at the bottom?
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39710785
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question