Return to VBA Code Examples

VBA Insert Row or Column

In this Article

  • Insert a Single Row or Column
    • Insert New Row
    • Insert New Column
  • Insert Multiple Rows or Columns
    • Insert Multiple Rows
    • Insert Multiple Columns
  • Insert – Shift & CopyOrigin
  • Other Insert Examples
    • Insert Copied Rows or Columns
    • Insert Rows Based on Cell Value
    • Delete Rows or Columns

This tutorial will demonstrate how to use VBA to insert rows and columns in Excel.

To insert rows or columns we volition utilise the Insert Method.

Insert a Single Row or Cavalcade

Insert New Row

To insert a single row, you tin can utilise the Rows Object:

Or you tin can use the Range Object along with EntireRow:

Insert New Column

Similar to inserting rows, nosotros can use the Columns Object to insert a column:

Or the Range Object, along with EntireColumn:

Insert Multiple Rows or Columns

Insert Multiple Rows

When inserting multiple rows with the Rows Object, you must enter the rows in quotations:

Inserting multiple rows with the Range Object works the same every bit with a single row:

Insert Multiple Columns

When inserting multiple columns with the Columns Object, enter the column messages in quotations:

Inserting multiple columns with the Range Object works the same as with a single column:

VBA Coding Made Easy

Stop searching for VBA lawmaking online. Learn more most AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding cognition and with many fourth dimension-saving features for all users! automacro

Learn More!!

Insert – Shift & CopyOrigin

The Insert Method has two optional arguments:

  • Shift – Which management to shift the cells
  • CopyOrigin – Which cell formatting to re-create (to a higher place, beneath, left, or right)

The Shift argument is irrelevant when inserting entire rows or columns. It only allows yous to indicate to shift down or shift to the right:

  • xlShiftDown – Shift cells down
  • xlShiftToRight – Shift cells to the right

Equally you tin encounter, you tin't shift up or to the left.

The CopyOrigin argument has 2 potential inputs:

  • xlFormatFromLeftorAbove – (0) Newly-inserted cells accept formatting from cells above or to the left
  • xlFormatFromRightorBelow (one) Newly-inserted cells have formatting from cells below or to the correct.

Permit's look at some examples of the CopyOrigin argument. Hither's our initial information:

vba insert row

This example volition insert a row, taking the formatting from the higher up row.

vba insert row above

This example will insert a row, taking the formatting from the below row.

vba insert row below

Other Insert Examples

Insert Copied Rows or Columns

If you'd like to insert a copied row, you lot would use lawmaking like this:

Here we copy Row 1 and Insert it at Row 5.

VBA Programming | Lawmaking Generator does work for you!

Insert Rows Based on Cell Value

This will loop through a range, inserting rows based on cell values:

Delete Rows or Columns

To delete rows or columns, only use the Delete method.