Solved

Excel VBA - issue naming sheets

Posted on 2011-03-03
8
310 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

832 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