when adding worksheet, how do I make sure it is always the first worksheet?

When adding a worksheet with VBA, how to I make sure the new worksheet is always the first worksheet in the workbook?
Sandra SmithRetiredAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Use a statement like this:

With ActiveWorkbook
    .Worksheets.Add Before:=.Worksheets(1)
End With

Open in new window

To make it the first sheet:

With ActiveWorkbook
    .Worksheets.Add Before:=.Sheets(1)
End With

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sandra SmithRetiredAuthor Commented:
Thank you,

Here is a subroutine that will make it the first sheet and ask to be renamed

Sub addsheet()
' addsheet Macro
' Keyboard Shortcut: Ctrl+a

Dim ActNm As String

With ActiveWorkbook.Sheets
    .Add Before:=Worksheets(1)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "Sheet1"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.