Solved

VBA Excel - Add sheet and rename

Posted on 2010-11-30
4
1,314 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 100 total points
ID: 34237781
Try this

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


Ed
0
 
LVL 17

Accepted Solution

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

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

Assisted Solution

by:Exceleved
Exceleved earned 200 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

777 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