Solved

Adding and naming Excel Worksheets

Posted on 1998-12-03
4
124 Views
Last Modified: 2010-05-03
I need a macro that adds a new sheet in excel and uses a cell to name it. It should be possible to do this as many times as possible.
0
Comment
Question by:panikos
  • 2
4 Comments
 
LVL 2

Expert Comment

by:cartti
ID: 1448083
Use this example as the basis of your macro:

Sub Add_Sheet()
    Sheets.Add().Name = Sheets(1).Range("A1").Value
End Sub
0
 

Author Comment

by:panikos
ID: 1448084
Returns an error "Object required". Also wouldn't this always look for sheet 1 rather than a sheet that has yet to be created.
0
 
LVL 2

Accepted Solution

by:
JiaH earned 100 total points
ID: 1448085
How about this one: (Add the new worksheet at the end of the worksheets and use the first one's A1 as the name, the better one is replace the 1 with it's name such as "Sheet1").

Sheets.Add(, After:=Worksheets(Worksheets.Count)).Name = Sheets(1).Range("A1").Value

0
 
LVL 2

Expert Comment

by:cartti
ID: 1448086
Regarding panikos's comment: What the code does is add a sheet calling it the name you have put in sheet 1, cell A1. What version of Excel have you ?

Regarding JiaH's answer: Besides being a ripoff of my answer, if panikos had problems syntaxly with my example, I find it hard to believe panikos will have any luck with yours
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 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