[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA Excel - Add sheet and rename

Posted on 2010-11-30
4
Medium Priority
?
1,364 Views
Last Modified: 2012-06-21
Dear Experts,

I have three lines in a part of a macro which simply add a new sheet and renames it

Sheets.Add
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "Orders"

My problem that sometimes when the macro add a sheet, it is not Sheet4 just Sheet3 for example, and it stops the running. Could you please advise how to do this simplier so maybe in one step adding and renaming? The target would be simply just adding a new sheet as "Orders"

thanks,
0
Comment
Question by:csehz
4 Comments
 
LVL 19

Assisted Solution

by:MINDSUPERB
MINDSUPERB earned 400 total points
ID: 34237781
Try this

Sub AddWorksheet()
Worksheets.Add().Name = "Orders"
End Sub


Ed
0
 
LVL 17

Accepted Solution

by:
gtgloner earned 800 total points
ID: 34237788
Sub Macro1()

    Sheets.Add
    ActiveSheet.Name = "Orders"
   
End Sub
0
 
LVL 8

Assisted Solution

by:Exceleved
Exceleved earned 800 total points
ID: 34237789
Sheets.Add
activesheet.Name = "Orders"

or

with sheets.add
.Name = "Orders"
'do something else
end with
0
 
LVL 1

Author Closing Comment

by:csehz
ID: 34237806
Thanks the solutions, for me seems simplier the option

Sheets.Add
ActiveSheet.Name = "Orders"

thanks,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

873 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