Solved

Excel VBA - issue naming sheets

Posted on 2011-03-03
8
319 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:Murray Brown
[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:Murray Brown
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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:Murray Brown
ID: 35046107
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

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