Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA: Add Sheet After Specific Sheet

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To add a new worksheet immediately after a specific sheet in Excel VBA, use the Worksheets.Add method with the After argument: Worksheets.Add After:=Worksheets("Sheet1"). This inserts a fresh worksheet directly to the right of the named sheet, regardless of where the active cell is. You can also reference the sheet by index number or by object variable. The steps below show the exact syntax, how to name the new sheet in the same line, and how to avoid the most common runtime errors.

What You'll Need

  • Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer). Labels can differ slightly by Excel version and region.
  • A workbook saved as .xlsm (macro-enabled) if you want to keep the code.
  • Basic familiarity with opening the VBA Editor (Alt+F11) and inserting a module.

Step-by-Step

  1. Open the VBA Editor. Press Alt+F11. In the Project Explorer, right-click your workbook, choose Insert > Module. A blank code window appears.
  2. Write the simplest statement. Type the following in the module:
    Sub AddSheetAfter()
        Worksheets.Add After:=Worksheets("Sheet1")
    End Sub
    This adds a new sheet immediately after the sheet named Sheet1. If your sheet has a different name, replace the text inside the quotes.
  3. Run the macro. Place the cursor inside the subroutine and press F5, or go back to Excel and use Developer > Macros, select AddSheetAfter, and click Run. The new sheet appears to the right of Sheet1 and becomes the active sheet.
  4. Name the new sheet in the same line (optional). If you want to avoid the default name (Sheet2, Sheet3, etc.), capture the new sheet in a variable:
    Sub AddNamedSheetAfter()
        Dim ws As Worksheet
        Set ws = Worksheets.Add(After:=Worksheets("Sheet1"))
        ws.Name = "Report"
    End Sub
    The Set line creates the sheet and returns a reference; the next line renames it. If a sheet named Report already exists, Excel raises a runtime error 1004. Use a unique name or check first.
  5. Use a sheet index instead of a name. If the target sheet's name might change, refer to its position:
    Worksheets.Add After:=Worksheets(1)
    This adds after the first sheet in the workbook (leftmost tab). Index 1 is always the first tab, regardless of its name.
  6. Add after the active sheet. To insert after whatever sheet the user is currently on:
    Worksheets.Add After:=ActiveSheet
    This is useful in buttons or event handlers where the target is not fixed.
  7. Add multiple sheets at once. The Count argument controls how many sheets are inserted:
    Worksheets.Add After:=Worksheets("Sheet1"), Count:=3
    Three new sheets appear immediately after Sheet1, in order. The first of the three becomes active.
  8. Handle a missing sheet name. If the named sheet does not exist, VBA raises error 9 (Subscript out of range). Wrap the call in a check:
    Sub SafeAddAfter()
        Dim targetName As String
        targetName = "Sheet1"
        On Error Resume Next
        Dim exists As Boolean
        exists = Not Worksheets(targetName) Is Nothing
        On Error GoTo 0
        If exists Then
            Worksheets.Add After:=Worksheets(targetName)
        Else
            MsgBox "Sheet " & targetName & " not found."
        End If
    End Sub
    This prevents the macro from stopping abruptly when the sheet is renamed or deleted.
  9. Save the workbook. Press Ctrl+S. Because the file contains a macro, save as .xlsm. If you save as .xlsx, Excel warns that the macro will be removed.

Common Mistakes

  • Using Sheets instead of Worksheets. Sheets includes chart sheets; Worksheets only includes worksheets. If you need to add after a chart sheet, use Sheets.Add After:=Sheets("Chart1"). Mixing the two can produce unexpected placement.
  • Forgetting the After argument. Worksheets.Add without After (or Before) inserts before the active sheet, not after your target. Always specify one.
  • Assuming the new sheet is named automatically. Excel assigns the next available default name (Sheet4, Sheet5, etc.). If your code later refers to "Sheet2", it may fail after the insertion shifts names. Use a variable or rename immediately.
  • Not qualifying the workbook. In a workbook with multiple open files, Worksheets refers to the active workbook. If the macro runs from an add-in or another workbook, the sheet may be added to the wrong file. Qualify with ThisWorkbook.Worksheets or Workbooks("Book1.xlsm").Worksheets.
  • Renaming to an existing name. Sheet names must be unique. Setting ws.Name = "Data" when a Data sheet exists throws error 1004. Check for duplicates or use a timestamp suffix.

Tips

  • Use a variable to hold the new sheet so you can set its name, tab color, or range values in the same procedure without searching for it later.
  • If you need the new sheet at the very end of the workbook, use After:=Worksheets(Worksheets.Count). If you need it at the very beginning, use Before:=Worksheets(1).
  • Turn off screen updating for macros that add many sheets: Application.ScreenUpdating = False at the start, then set it back to True at the end. This speeds up execution and reduces flicker.
  • Test on a copy of the workbook. Inserting sheets changes tab order and can break formulas that reference sheet positions.
  • If you plan to share the workbook, avoid hard-coded sheet names in the macro; read the name from a cell or use an index.

Troubleshooting

Error 9: Subscript out of range. The sheet name in Worksheets("Sheet1") does not exist. Check spelling, including spaces, and confirm the sheet is a worksheet, not a chart sheet. Use the index number if the name is uncertain.

Error 1004: Application-defined or object-defined error. This often happens when the name you assign to the new sheet already exists, or when the workbook is protected. Unprotect the workbook (Review > Unprotect Workbook) or choose a different name.

The macro runs but no sheet appears. The new sheet may be added to a different workbook. Qualify the Worksheets object with ThisWorkbook or the specific workbook name. Also check that Application.ScreenUpdating is not left off from a previous run.

The new sheet is in the wrong place. Confirm you used After:= and not Before:=. If you used ActiveSheet, the active sheet may not be the one you expected; activate the target sheet first or use its name.

Macro is disabled. Excel may block macros from files downloaded from the internet. Right-click the file in File Explorer, choose Properties, and check Unblock. Also ensure the Trust Center macro settings allow macros (File > Options > Trust Center > Trust Center Settings > Macro Settings).

Frequently Asked Questions

Can I add a sheet after the last sheet in the workbook?

Yes. Use Worksheets.Add After:=Worksheets(Worksheets.Count). This places the new sheet at the far right.

How do I add a sheet after a specific sheet in another workbook?

Qualify the workbook: Workbooks("Book2.xlsx").Worksheets.Add After:=Workbooks("Book2.xlsx").Worksheets("Sheet1"). The workbook must be open.

Does the new sheet become the active sheet?

Yes, by default the newly added sheet becomes active. If you want to keep the original sheet active, store ActiveSheet before adding and reactivate it afterward.

Can I add a sheet after a chart sheet?

Yes, but use the Sheets collection instead of Worksheets: Sheets.Add After:=Sheets("Chart1"). The new sheet will be a worksheet by default.

Why does my macro add the sheet before the target instead of after?

You likely omitted the After argument or used Before. Check the line for After:= and ensure the target sheet reference is correct.

Can I name the new sheet at the same time as adding it?

Not in a single method call. You must add the sheet, capture the returned object, then set its Name property. The two-line pattern with Set ws = Worksheets.Add(...) followed by ws.Name = "..." is the standard approach.