• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1411
  • Last Modified:

Excel VBA - add new sheet after sheet 1 and name it

Hi

What VBA code would I use to add a new Excel sheet directly after sheet 1 and then name that sheet "Data"
Thanks
0
Murray Brown
Asked:
Murray Brown
2 Solutions
 
SiddharthRoutCommented:
Try this

Sub Sample()
    Dim NewSht1 As Worksheet
    Sheets.Add after:=Sheet1
    Set NewSht1 = ActiveSheet
    NewSht1.Name = "Data"
End Sub

Open in new window


Sid
0
 
StephenJRCommented:
Perhaps this?

Sheets.Add(After:=Sheets(1)).Name = "Data"
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you both
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now