Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-28
3
Medium Priority
?
1,285 Views
Last Modified: 2012-08-13
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
Comment
Question by:Murray Brown
[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
3 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 1200 total points
ID: 34996324
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
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 800 total points
ID: 34996328
Perhaps this?

Sheets.Add(After:=Sheets(1)).Name = "Data"
0
 

Author Closing Comment

by:Murray Brown
ID: 34996406
Thank you both
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

705 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