Solved

Adding and naming Excel Worksheets

Posted on 1998-12-03
4
126 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 596
Spell Check in VB6 13 127
VB6 ListBox Question 4 50
checkbox to hide entire section 10 43
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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