Return to VBA Code Examples

VBA Routine to Add and Name Worksheets

In this Article

  • Add Sheet
  • Add together Sheet with Name
    • Create New Sail with Name from a Cell
  • Add Sheet Before / Afterwards Another Sail
    • Insert Sheet After Some other Sheet
    • Add together Sheet To End of Workbook
    • Add Canvas To Get-go of Workbook:
  • Add Canvass to Variable
  • More than Add Sheet Examples
    • Create Sail if it Doesn't Already Be
    • Create Worksheets From List of Names
  • VBA Coding Made Easy

This tutorial will discuss how to add / insert worksheets using VBA.

Add Sheet

This simple macro will add a Canvas before the ActiveSheet:

After inserting a Sheet, the new Canvas becomes the ActiveSheet. Y'all can and then use the ActiveSheet object to work with the new Sheet (At the bottom of this article we will show how to insert a new sheet straight to a variable).

Add Sail with Name

You can also ascertain a Canvas name equally y'all create the new Sheet:

Create New Sheet with Name from a Prison cell

Or use a jail cell value to name a new Canvass:

Add Sheet Before / After Some other Canvass

Y'all might also desire to choose the location of where the new Sheet will be inserted. You can use the After or Before properties to insert a sail to a specific location in the workbook.

Insert Canvas Later on Another Sail

This code volition insert the new sheet AFTER another sail:

This will insert a new Canvass AFTER another sheet and specify the Sheet name:

Observe the actress parenthesis required in the second example (the get-go example will generate an error if the second parenthesis are added).

or Before:

In these examples we explicitly named the Sheet used to determine the sheet location. Frequently you'll desire to use the Sheet Alphabetize number instead, so that yous can insert the canvas to the beginning or finish of the Workbook:

Add Canvass To End of Workbook

To add a Sheet to the end of the workbook:

Tired of Searching for VBA Code Examples? Try AutoMacro!

Add together Sail To Commencement of Workbook:

To add together a Canvass to the offset of the workbook:

Add Sheet to Variable

This code assigns the new Sheet to a variable as the canvass is created:

From here you can reference the new canvass with the variable 'ws':

More Add together Sail Examples

Create Sheet if information technology Doesn't Already Be

You might want to create a sheet merely if it doesn't already exist.

Great Production. AutoMacro doesn't just write your code, information technology teaches as yous go!" - Tony, UK

Acquire more than

Read our 900+ Reviews

Create Worksheets From List of Names

The following routine will expect at the contents of a single column set Excel worksheets within the current workbook with these names. It makes a call to another role to see if a canvass with that proper name already exists, and if so the canvass isn't created.

So if we take the following text in cells A1:A30 in Sheet two:

adding sheets

Then the following sheets will be created:

adding sheets 2

Note that although "Dog" appears twice, only one canvas is created.

To download the .XLS file for this tutorial, click here.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more than about AutoMacro – A VBA Lawmaking Architect that allows beginners to code procedures from scratch with minimal coding knowledge and with many fourth dimension-saving features for all users!

alt text

Acquire More than!


<<Return to VBA Examples