PTR logo

Blog Post

VBA Code Help

VBA Code Help
IR

Author

Ian Roberts

Date

September 21, 2016

Length

1 min

This is the first of a series of blogs containing useful pieces of code.

Adding A New Worksheet into A Workbook

The following piece of code allows you to add a new Worksheet into your Workbook.

Sub NewWorksheet()

    Sheets.Add    End Sub

We can develop this code to allow us to choose a name for our new Worksheet.

Sub NewWorksheetAndName()    Dim strName As String        strName = InputBox("What would you like to name your sheet?")

    Sheets.Add    ActiveSheet.Name = strName    End Sub

We can develop this further to allow us to add the new Worksheet after the last Worksheet in the Workbook.

Sub NewWorksheetAfterLastSheet()    Dim strName As String        strName = InputBox("What would you like to name your sheet?")

    Sheets.Add after:=Sheets(Sheets.Count)    ActiveSheet.Name = strName    End Sub

For more help with Excel VBA, keep an eye on our blog, or come and join us on one of our courses, Introduction to Excel VBA & Advanced Excel VBA.

Share This Page

IR

Ian Roberts

Technical Director

Ian is an incredibly talented solutions architect. He has over 15 years of experience working with data, as part of a broader IT career spanning over 20 years.

Latest Articles

PTR FAQs

See our FAQs or get in contact for more information on any of our services, solutions, or to start your PTR journey.

Ready to take your business to the next level?

Reach out to our team of experts and learn more about our consultancy and training services.