VBA Excel - Add sheet and rename

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,
LVL 1
csehzIT consultantAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
gtglonerConnect With a Mentor Commented:
Sub Macro1()

    Sheets.Add
    ActiveSheet.Name = "Orders"
   
End Sub
0
 
MINDSUPERBConnect With a Mentor Commented:
Try this

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


Ed
0
 
ExcelevedConnect With a Mentor Commented:
Sheets.Add
activesheet.Name = "Orders"

or

with sheets.add
.Name = "Orders"
'do something else
end with
0
 
csehzIT consultantAuthor Commented:
Thanks the solutions, for me seems simplier the option

Sheets.Add
ActiveSheet.Name = "Orders"

thanks,
0
All Courses

From novice to tech pro — start learning today.