There are two quick ways to delete rows and columns from tables in Word for the web.
- If you’re not already in Editing View, click Edit Document > Edit in Word for the web.
- Click anywhere in the table row or column you want to delete.
Here is the example VBA macro to delete the first few Columns using Do while Loop. This will delete the first 10 records using For loop in VBA. Sub sbVBSToDeleteEntireColumnDowhileLoop Dim iCntr iCntr = 10 ' Last Column Do While iCntr = 1 Columns(iCntr).EntireColumn.Delete iCntr = iCntr - 1 Loop End Sub.
If you want to remove more than one row or column, select a cell in each row or column you want to delete.
- Under Table Tools, click Layout, and then click either Delete Row or Delete Column.
The other quick way to delete rows and columns is to select the contents of a cell in a row or column you want to delete. This opens a pop-up menu. Click Delete and then click either Delete Row or Delete Column.
Excel Functions Tutorials
- Financial Functions in Excel
- Logical Functions in Excel
- TEXT Functions in Excel
- Lookup Reference in Excel
- Maths Functions in Excel
- Date and Time Function in Excel
- Statistical Function in Excel
- Information Functions in Excel
- Excel Charts
- Excel Tools
- Excel Tips
- VBA
Related Courses
![Vba Vba](/uploads/1/2/5/1/125191152/545039712.png)
Excel VBA Delete Column
We perform many actions in excel like cut, copy, paste, add, delete, insert and many such things we do on a regular basis. We can use all of these actions using VBA Coding. One of the important concepts we need to learn is in VBA is “deleting column”. In this article, we will show you how to use this Delete Column option in VBA.
What Does Delete Column Do in Excel VBA?
As the name says it will delete the specified column. To perform this task we need to first identify which column we need to delete. Selection of column to delete is different from one scenario to another, so we will cover some of the important and often faced scenarios in this article.
Deleting the columns is easy. First, we need to use the COLUMNS property to select the column, so below is the syntax of Column Delete method in VBA.
Columns (Column Reference).Delete
So we can construct the code like this:
This will delete the column number 2 i.e. Column B.
If we want to delete multiple columns we cannot enter columns, we need to reference the columns by column headers i.e. alphabets.
This will delete the column from A to D i.e. first 4 columns.
Like this, we can use the “Delete Column” method in VBA to delete the particular columns. In the below section we will see more examples to understand it better. Read on.
Examples of Excel VBA Delete Column Method
Below are the examples to delete columns using VBA.
Example #1 – Using Delete Method
Assume you have the datasheet something like the below.
If we want to delete the column month “Mar”, first select the columns property.
Code:
Mention the column number or alphabet. In this case it is either 3 or C.
Code:
Use the Delete method.
Note: you won’t get intellisense list to select the Delete method, just type “Delete”,
Code:
Or you can enter the column address like this.
Code:
Run this Code using F5 key or you can run manually and see the result.
Both the codes will do the same job of deleting the mentioned column.
Excel VBA Certification Course35+ Courses | 120+ Hours of Videos | Full Lifetime Access | Certificate of Completion
4.9 (1,353 ratings)
4.9 (1,353 ratings)
Related Courses
VBA Macros CourseAdvanced Excel CourseTableau Certification CourseIf we want to delete multiple columns we need to mention them in alphabets, we cannot use column numbers here.
If we want to delete the columns 2 to 4 we can pass the code like the below.
Code:
Run this code manually through run option or press F5 key, this will delete the columns “Feb”, “Mar”, and “Apr”.
Example #2 – Delete Columns with Worksheet Name
The above is the overview of how to delete columns using VBA code. However, that is not the good practice of deleting columns, without referring the worksheet name it is dangerous to blindly delete the column.
If you have not mentioned the worksheet name then whichever sheet is active it will delete columns of that sheet.
First, we need to select the worksheet by its name.
Code:
After selecting the sheet we need to select the columns. We can also select the columns by using VBA RANGE object as well.
Code:
This will delete the columns B to D, of the worksheet “Sales Sheet”. For this code it doesn’t matter which is active, still, it will delete the mentioned columns of that sheet only.
We can also construct the VBA code in the single line itself.
Code:
This also deletes the columns “B to D” without selecting the worksheet “Sales Sheet”.
Example #3 – Delete Blank Columns
Assume you have data which has alternative blank columns like the below.
So, delete every alternative column we can use below code.
Code:
Run this code using F5 key or manually then, it will delete all the alternative blank columns and our data will look like this.
Note: This works only for alternative blank columns.
Example #4 – Delete Blank Cells Columns
Now look at this example. There are certain situations where we need to delete the entire column if any of the blank cells found in the data range. Consider the below data for an example.
All the yellow-colored cells are blank. So here my requirement is to delete all the blank cells columns. Below code will do that.
Code:
Let me explain this code line by line for you.
Our data is there from A1 to F9, so first I need to select that range and below code will that.
In this selected range of cells, I need to select the cells which are blank. So to select blank cell we need to special cells property and in that property, we have used cell type as blank.
Next, it will select all the blank cells and in the selection, we are deleting the entire column of the selection.
So our end result will look like this.
Wherever it has found the blank cell it has deleted those blank cells entire column.
You can download this Excel VBA Delete Column here – VBA Delete Column Template
Recommended Articles
This has been a guide to VBA Delete Column. Here we learn 4 different methods to delete columns using Excel VBA code along with practical examples and downloadable codes. Below are some useful excel articles related to VBA –
![Excel vba delete columns Excel vba delete columns](/uploads/1/2/5/1/125191152/369176037.gif)
- 35+ Courses
- 120+ Hours of Videos
- Full Lifetime Access
- Certificate of Completion
- Basic Microsoft Excel Training
- MS Excel 2010 Training Course: Advanced
- Microsoft Excel Basic Training
- Microsoft Excel 2013 – Advanced
- Microsoft Excel 2016 – Beginners
- Microsoft Excel 2016 – Advanced