Name

worksheets.Add(Before, After, Count, Type)

Synopsis

Creates one or more worksheets. If you create a single worksheet, it is the active sheet. If you create more than one worksheet, the last sheet created is the active sheet.

Argument

Settings

Before

Specifies an existing worksheet if you want to place the new worksheet before that sheet.

After

Specifies an existing worksheet if you want to place the new worksheet after that sheet.

Count

Specifies the number of sheets to be added if you want to create more than one sheet.

Type

Use xlChart to insert a chart, xlExcel4MacroSheet to insert a macro sheet, or the path to a template if you are inserting a sheet based on an existing template.

The following code creates two worksheets after the WombatBattingAverages worksheet:

ActiveWorkbook.Sheets.Add After:=Worksheets("WombatBattingAverages"), Count:=2

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.