In this article, we will explain how to insert rows or columns in excel sheet using VBA macro code. Insert method is used to insert rows or columns.
Insert Single Row
At given Position – Suppose you have to insert a new row at row index 8, you can use any of the following VBA commands to do that.
Rows(8).Insert
or
Range("A8").EntireRow.Insert
or
Range("8:8").Insert
At Active Cell Position – If you want to insert a new row above the active cell, use the below given VBA code line. It will insert a new row above the active cell.
ActiveCell.EntireRow.Insert
Insert Single Column
At given Position –Suppose you have to insert a new column at D position, you can use any of the following excel macro code to do that.
Columns(4).Insert
or
Range("C4").EntireColumn.Insert
or
Range("D:D").Insert
At Active Cell Position – If you want to insert a new column left to the active cell, use the below given command. It will insert a new column left to the active cell.
ActiveCell.EntireColumn.Insert
Insert Multiple Rows
Suppose you have to insert 3 rows at 8, 9 & 10 position, use any of the below given commands.
Range("8:10").Insert
or
Rows("8:10").Insert
or
Range("A8:A10").EntireRow.Insert
Insert Multiple Columns
Suppose you have to insert 3 columns at C, D & E position, use any of the below given commands.
Columns("C:E").Insert
or
Range("C1:E1").EntireColumn.Insert