Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding and naming Excel Worksheets

Posted on 1998-12-03
4
Medium Priority
?
131 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 300 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

926 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