How to Insert Row or Column in Excel VBA?

In this post, let’s have a look at examples in Excel VBA demonstrating how to insert row or column in your Microsoft Excel spreadsheet.

How to Insert Row or Column in Excel VBA?

How to Insert Row or Column in Excel VBA?

To insert rows or columns we can use the Insert Method in Excel.

Insert a Single Row

Insert New Row

To insert a single row, use this VBA code.

Code:

Rows(4).Insert

Insert Entire Row

To insert an entire row, use the below VBA code.

Code:

Range("b4").EntireRow.Insert

Insert New Column

To insert new column, use the below code snippet

Code:

Columns(4).Insert

Insert an Entire Column

To insert an EntireColumn in your excel worksheet, use the below code snippet.

Code:

Range("b4").EntireColumn.Insert

Insert Multiple Rows or Columns

Insert Multiple Rows

To insert multiple rows

Code:

Rows("4:6").Insert

Insert Multiple Columns

To insert Multiple Columns

Code:

Columns("B:D").Insert

Insert Rows Based on Cell Value

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

Sub InsertRowswithSpecificValue()

Dim cell As Range

For Each cell In Range("b2:b20")

    If cell.Value = "insert" Then

        cell.EntireRow.Insert

    End If

Next cell

End Sub

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021