Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1313
  • 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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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