Solved

Excel VBA - issue naming sheets

Posted on 2011-03-03
8
307 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

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

19 Experts available now in Live!

Get 1:1 Help Now