Inserting multiple rows with VBA in Excel takes one line of code: Range("A5").Resize(3).EntireRow.Insert puts three blank rows above row 5. Whether you need a fixed block of rows, a number typed into a cell, or rows inserted between every existing row, a short macro does it in a fraction of the time manual inserting takes. This guide walks through the setup and the most useful code patterns.

What You'll Need

  • Excel for Windows or Mac (the VBA editor is not available in Excel for the web).
  • A workbook saved as a macro-enabled file (.xlsm), or a willingness to save it that way.
  • The Developer tab visible on the ribbon. If it is missing, right-click anywhere on the ribbon, choose Customize the Ribbon, and tick Developer in the right-hand list. Menu labels can differ slightly between Excel versions.
  • Basic familiarity with pasting code into a module — everything you need is described below.

Step-by-Step

  1. Open the VBA editor. Press Alt + F11 (on Mac, click Tools > Macro > Visual Basic Editor or press Option + F11). A new window opens with your workbook listed on the left under Project Explorer.
  2. Insert a module. In the editor menu, click Insert > Module. A blank white code window appears. This is where all the code below goes.
  3. Start with a fixed block of rows. Paste this and change the numbers to suit your sheet:
    Sub InsertMultipleRows()
        Rows("5:7").Insert Shift:=xlDown
    End Sub

    This inserts three blank rows starting at row 5, pushing the existing rows down.
  4. Use a cell value for the row count. If you want the number of rows to come from a cell (for example, the number typed in cell D1):
    Sub InsertRowsFromCell()
        Dim n As Long
        n = Range("D1").Value
        If n < 1 Then Exit Sub
        Range("A5").Resize(n, 1).EntireRow.Insert
    End Sub
  5. Insert rows relative to the selected cell. To insert a block directly above whatever cell is active:
    Sub InsertRowsAboveSelection()
        Dim n As Long
        n = 5 ' change to your row count
        Selection.Resize(n, 1).EntireRow.Insert
    End Sub
  6. Insert a blank row between every existing row (reverse loop). When inserting many rows in a loop, always count backwards so the target range does not shift under you:
    Sub InsertRowBetweenEach()
        Dim i As Long
        Dim lastRow As Long
        lastRow = Cells(Rows.Count, "A").End(xlUp).Row
        For i = lastRow To 2 Step -1
            Rows(i).Insert Shift:=xlDown
        Next i
    End Sub
  7. Run the macro. Click anywhere inside the Sub you want, then press F5, or return to Excel and use Developer > Macros, select the macro name and click Run.
  8. Save as a macro-enabled workbook. Press F12 in Excel, and in the Save As dialog choose Excel Macro-Enabled Workbook (*.xlsm) from the file type list. A plain .xlsx file will silently drop the code.

Common Mistakes

  • Looping forwards when inserting rows. A forward loop inserts a row, which shifts everything down, so the next iteration hits a row that has already moved. Loop backwards with Step -1.
  • Forgetting to resize before Insert. Range("A5").EntireRow.Insert inserts only one row. You must resize the range to n cells first, as shown above, or reference multiple rows like Rows("5:7").
  • Not specifying the worksheet. Without Worksheets("Sheet1"). in front of the range, the code acts on whichever sheet is active when it runs, which may not be the one you intended.
  • Inserting inside a formatted Excel Table. VBA row insertion into a ListObject behaves differently from a plain range and can error out. Either target a cell just above the table, or use the table's ListRows.Add method instead.
  • Saving as .xlsx. The macro works during the session but disappears when the file is reopened.

Tips

  • Turn off screen updating for large loops — Application.ScreenUpdating = False before the loop and = True after — to make it dramatically faster.
  • For very large blocks (thousands of rows), a single Rows("5:1004").Insert is far faster than a loop that inserts one row at a time.
  • Add Option Explicit at the top of the module. It forces you to declare variables and catches typos that would otherwise create silent bugs.
  • Undo does not work after a macro runs, so save the workbook before testing new code, or work on a copy of the file.
  • To clear the formats Excel copies from the row above during insertion, follow the Insert with Rows("5:7").ClearFormats if you need genuinely blank rows.

Troubleshooting

  • "Sub or Function not defined" or the macro does not appear in the Macros list: make sure the code was pasted into a standard Module (Insert > Module), not into a Sheet or ThisWorkbook code window, and that the Sub has a name.
  • "Run-time error '1004'" on Insert: the usual causes are the sheet being protected (unprotect it with Review > Unprotect Sheet) or the target range being inside an Excel Table. Check both.
  • Nothing happens when you press F5: your cursor may be outside the Sub. Click inside the procedure body, then press F5 again.
  • Wrong sheet got the rows: the macro used the active sheet. Qualify the range with the sheet name, e.g. Worksheets("Data").Rows("5:7").Insert.
  • Macros disabled on reopen: Excel blocks macros in macro-enabled files until you click Enable Content in the yellow security bar. If the file was saved as .xlsx, re-save it as .xlsm — the code is already lost and must be pasted in again.
  • Rows inserted in the wrong place in a loop: confirm the loop runs from the last row down to 2 with Step -1, and that lastRow is calculated before the loop starts, not inside it.

Frequently Asked Questions

Can I insert multiple rows at once with a keyboard instead of VBA?

Yes — select the same number of rows as you want to insert (for example, select three row headers), then press Ctrl + Shift + + (or Control + I on Mac). VBA is worth it when you repeat the task often or need it automated.

Does the inserted row copy formatting?

By default, rows inserted with .Insert inherit formatting from the row above. Use .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow to copy from below instead, or clear formats afterwards.

How many rows can I insert with VBA?

Up to the worksheet limit — a sheet holds 1,048,576 rows, and insertion fails if the shift would push existing data past that boundary. Practically, inserting thousands of rows in one call is fast; the slow part is looping one at a time.

Why does my loop skip every other row?

Because it runs forwards. Each inserted row pushes the data down one position, so the loop index lands on a row it already processed. Reverse the loop with Step -1.

Can I assign the macro to a button?

Yes. Go to Developer > Insert, pick a Button (Form Control), click where you want it on the sheet, and select your macro from the list that appears. Clicking the button then runs the code.

Will this work in Excel for the web?

No. Excel for the web cannot create or run VBA macros. Use the desktop version of Excel for Windows or Mac.