Solved

Adding and naming Excel Worksheets

Posted on 1998-12-03
4
123 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

Suggested Solutions

Title # Comments Views Activity
VBA Check for Character 9 69
Vb.net 2008 2 49
VBA open file from excel cell 4 33
VBS file using code from 2nd file (txt or vbs) 4 24
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now