Excel: Sample Macro to Insert Multiple Rows

Ask a question

Microsoft Excel hosts a number of features that enables users to create worksheets completely tailored to their needs. Among these functionalities is the ability to create a macro, which allows users to make calculations and data manipulations without going through repetitive motions.

Insert Multiple Rows into Excel Worksheet

Excel Task

The below tip will enable you to insert multiple rows between existing rows in an Excel spreadsheet. This macro will enable you to insert a set amount of blank rows into your spreadsheet, and can be modified according to your needs.

Before Macro:

After Macro:





Sample Macro

Here is the macro code needed to perform the above task:
Sub test()    
Dim j As Long, r As Range
j = InputBox("type the number of rows to be insered")
Set r = Range("A2")
Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
Set r = Cells(r.Row + j + 1, 1)
MsgBox r.Address
If r.Offset(1, 0) = "" Then Exit Do

End Sub
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team