Solved

CodeName reference

Posted on 2013-12-10
6
169 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

636 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