Solved

CodeName reference

Posted on 2013-12-10
6
164 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
6 Comments
 
LVL 33

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 33

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 80

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 31

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now