[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA Excel - Add sheet and rename

Posted on 2010-11-30
4
Medium Priority
?
1,352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

656 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