Insert Multiple Columns Using Macros (VBA) in Excel:
In this tutorial, we will guide you to learn the steps to Insert Multiple Columns Using Macros (VBA) in Excel Office 365 with an example. Get an official version of MS Excel from the following link: https://www.microsoft.com/en-in/microsoft-365/excel
Steps to Insert Multiple Columns Using Macros:
To insert multiple columns in Excel using Macros, follow the below steps.
- On the Developer Tab , select the Visual Basic option under the code section.
- Now, you need to make sure that the sheet1 is selected. Then, enter the below code.
VBA code for inserting multiple columns
Sub InsertMultipleColumns()
Dim numColumns As Integer
Dim counter As Integer
‘You need to select the current column
ActiveCell.EntireColumn.Select
On Error GoTo Last
numColumns = InputBox(“Enter number of columns to insert”, “Insert Columns”)
‘You need to keep on insert columns until we reach the desired number
For counter = 1 To numColumns
Selection.Insert Shift:=xlToRight, CopyOrgin:=xlFormatFromRightorAbove
Next counter
Last: Exit Sub
End Sub
- You need to save the code by selecting it. Then close the window.
- You need to select any cell where you want to insert columns. Then, go to the Developer Tab , choose the Macros option.
- You have to make sure that your Macro is selected and click the Run button.
- It will open the Insert Columns dialog box , you have to enter the number of columns that you need to add in the text box. Then, hit the OK button.
- Now, the specified number of columns will be added to the spreadsheet.
Summary:
In this tutorial, we guided you to learn the steps to Insert Multiple Columns Using Macros (VBA) in Excel Office 365 with an example. Give your suggestions in the below comment section. Thanks for visiting Geek Excel. Keep Learning!!
Top comments (0)