Solved

Excel VBA - issue naming sheets

Posted on 2011-03-03
8
316 Views
Last Modified: 2012-05-11
Hi

I have VBA code (behind Sheet1) that adds new sheets each time it is run (see code below).
The problem is that the sheet numbers are getting bigger and bigger (eg Sheet34)
Is there a way to make the first sheet "Sheet2"
Sheets.Add after:=Sheet1
 Set NewSht1 = ActiveSheet

Open in new window

0
Comment
Question by:murbro
[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
8 Comments
 
LVL 3

Expert Comment

by:babesia
ID: 35031189

Dim ws As Worksheet
Set ws = Sheets.Add
ws.Name = "Sheet2"
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 35031192
Sheets.Add after:=Sheet1
 Set NewSht1 = ActiveSheet
NewSht1.name = "Sheet2"


NG,
0
 

Author Comment

by:murbro
ID: 35031223
Thanks. I forgot to mention that I am naming the sheet already. The name is a date, but the VBE still shows each sheet as Sheet33 etc
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 13

Expert Comment

by:nike_golf
ID: 35031860
I believe you can't change that name as it's how the system recognizes them, probably wrong here.

If you're already naming the sheets then why not refer to them by name?

NG,
0
 
LVL 6

Accepted Solution

by:
TinTombStone earned 500 total points
ID: 35032492
You can change the vbe code name:

ThisWorkbook.VBProject.VBComponents("Sheet1").Name = "NewCodeName"

0
 
LVL 13

Expert Comment

by:nike_golf
ID: 35033191
I might be missing the question here could you elaborate a little more?

NG,
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35034856
Idle curiosity - why do you need to change the CodeName?
0
 

Author Closing Comment

by:murbro
ID: 35046107
Thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

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