VBA Delete Columns in range Excel Macro Example Code

Home/VBA/VBA Delete Columns in range Excel Macro Example Code

VBA code to delete Columns in range example will helps to delete empty Columns in specific range from excel worksheet. We can use Delete method of Columns to delete the Columns in a range. In this example we will see how to delete the Columns from a range in excel worksheet using VB. Excel VBA Macro code for deleting Columns in a range should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

VBA code to delete Columns in a range

Here is the Example VBA syntax and Example VBA Macro to delete Columns in range from excel worksheets. This will help you to know how to delete specific Columns in a range from Excel workbook using VBA.

VBA delete Columns in range: Syntax

Following is the VBA syntax and sample VBA code to delete Columns in a range from worksheet using VBA. We are using the Delete method of the Columns object of worksheet.


Here Columns.delete method will delete the Column in the worksheet..

Delete Columns in Range: Examples

The following VBA code is to delete Columns in range A10 to D20 .

Sub sbVBS_To_Delete_Columns_In_Range()
Dim iCntr
Dim rng As Range
Set rng = Range("A10:D20")
For iCntr = rng.Column + rng.Columns.Count - 1 To rng.Column Step -1
End Sub 

Instructions to run the VBA code to delete Columns in range

Please follow the below steps to execute the VBA code to delete Columns in range from Excel worksheets.
Step 1: Open any Excel workbook
Step 2: Press Alt+F11 – This will open the VBA Editor
Step 3: Insert a code module from then insert menu
Step 4: Copy the above code and paste in the code module which have inserted in the above step
Step 5: Enter some sample data in range A1 to D20 in any column.
Step 6: Now press F5 to execute the code

Now you can observe that the all Columns are deleted from worksheet in in Range A10 to D20.

Explained VBA Code to Delete Columns in a range

Start writing the Excel VBA Macro to delete Columns in a particular range.
Sub sbVBS_To_Delete_Columns_In_Range()

‘Declaring a variable iCntr as Long to store the Column number iteration to use in for loop.
Dim iCntr As Long
‘Declaring range variable rng to set the range
Dim rng As Range

‘Assigning the range A10 to D20 to rng range object
Set rng = Range(“A10:D20”)

‘Looping through the Columns in the range from last to first. Here step statement will helps.
For iCntr = rng.Column + rng.Columns.Count – 1 To rng.Column Step -1
‘And deleting the Columns

End Sub
Ending the sub procedure to delete Columns in a range.

Related Resource External VBA Reference
Excel VBA Reference Project Management Reference
VBA Reference:
Excel Reference:
By |April 22nd, 2014|VBA|0 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

Leave A Comment

Related pages

project dashboard ppthow do you delete blank rows in excelproject plan calendar template excelxls macro programmingagenda excel templatevba sumifsexcel macro passwordhow to make a 100 stacked bar chart in excelwhat is the meaning of vlookupexcel print macroprotect workbook in excel 2007vba range objectexcel workbook protectionvbscript in exceluse of vlookup function in excelsumif syntaxhow to delete comment in excelexcel vba global variablevba macro tutorialhlookup explainedexcel vba countifhow to unlock an excel spreadsheet for editingscripting.filesystemobject vbaexcel vba division remainderexcel formulas and examplesadvanced vba programmingsort excel column alphabeticallyhow to merge cells excel 2010software project plan template exceladvanced excel vba examplesddl commands in sql servercopyfromrecordset vbavba programming basicsexcel add multiple rowsgoto statement vbasql select from excel sheetvba excel cell formatvba left stringactivate hyperlinks in excelrefresh pivot table in vbavba activexfor each in vbaadoinexcel lookup functionsto remove duplicates in excelpivoting tables in excelexcel formulas list 2007iferror formuladim as workbookvba print worksheethow to merge sheets in excelunmerge cellexcel chart dashboardddl statements in sqlhow to prepare dashboard in excel 2007unhide columns in excel 2007excel vba picturehow to create a vlookup formula in excel 2010vba query tableconsolidate in exceleliminate duplicates in excel 2010excel resource allocation templatehow to alphabetize rows in excelexcel vba booleanvba timer functionmsgbox vbyesnoddl dmlmultiple if then statements in excelexcel substitute formulahow to update hyperlinks in excelshortcut to insert row in excelvisual basic messageboxexcel practice tests for interviewshow do you unhide columns in excel 2013vba promptvba filesystemobjectlessons learned template powerpointexcel merge worksheets into oneexcel formulas for analysts