VBA code to Delete multiple Columns example will help us to delete multiple Columns from excel worksheet. We can use Delete method of Columns to delete the multiple Columns. In this example we will see how to delete the multiple Columns in excel worksheet using VBA. VBA code for deleting multiple Columns macro should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.
VBA code to delete multiple Columns
Here is the Example VBA syntax and Example VBA Macro to delete multiple Columns from excel worksheets. This will help you to know how to delete specific and multiple Columns from Excel workbook using VBA.
VBA Delete multiple Columns: Syntax
Following is the VBA Syntax and sample VBA code to delete multiple Columns from worksheet using VBA. We are using the Delete method of the Columns object of worksheet.
Here Column Names are your Column Names to delete. And EntireColumn.Delete method will delete the Entire Columns from the Excel spreadsheet.
Delete multiple Columns using VBA: Examples
The following VBA code is to delete multiple Columns from the worksheet. This code will delete the multiple Columns (A to C) which we have mentioned in the code.
Sub sbVBS_To_Delete_Multiple_Columns () Columns("A:C").EntireColumn.Delete End Sub
Instructions to run the VBA code to delete multiple Columns
Please follow the below steps to execute the VBA code to delete multiple Columns from worksheets.
Step 1: Open any existing 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 Column A to E
Step 6: Now press F5 to execute the code
Now you can observe that the entire Columns from A to C are deleted from worksheet.
Explained VBA Code to Delete Multiple Columns:
Starting program and sub procedure to write VBA code to delete entire Column from sheet.
‘Specifying the Columns to delete and Deleting the Columns using EntireColumn.Delete method.
Ending the sub procedure to delete entire Column.
Here Columns(“A:C”) is to tell excel to delete Columns from A to C of the worksheet. And Delete method will delete the all specified Columns form the worksheet.
Delete Specific Multiple Columns using VBA: Examples
Here is the following VBA code is to delete specific multiple Columns from the worksheet. This code will delete the multiple specific Columns (A, C, H, K to O and Q to U) which we have mentioned in the code.
Sub sbVBS_To_Delete_Specific_Multiple_Columns() Sheets("Sheet1").Range("A:A,C:C,H:H,K:O,Q:U").EntireColumn.Delete End Sub
The above example delete the columns A, C, H, K to O and Q to U from the sheet named ‘Sheet1’.
I tried this code, but it gives me an syntax error
I do have data available from A to Z
Can someone assist
This code should work, please provide the code which you are testing:
Hi, I need to delete random columns (ex. A,C,G,H). I tried doing it like you explained with the multiple random rows but it didn’t work
You can use the below procedure to delete specific columns:
Please note: Always store all the Column names in an array variable(arrCol) in ascending order.
How can I delete multiple columns for columns A, C, H, K-O, Q-U. Column K-O means column K to O. Thank you.
I have updated the post with the example. Please check the last example to delete multiple specific columns from the excel workbook sheet.
i have data of around 900 columns and i need to delete every 3 columns after first column, how do i do this…. eg: i have to leave column 1 and delete 2,3 &4 and leave column 5 and delete 6, 7, & 8 and leave 9 and so on….. help me….
Please find the below code to delete columns as per above mentioned criteria.
‘Function to find out column name from column number
‘For more detail: http://analysistabs.com/excel-vba/column-number-name/
Function find_Column_Number(ByVal ColumnNumber As Integer)
find_Column_Number = Replace(Replace(Cells(1, ColumnNumber).Address, “1”, “), “$”, “)
Will you please help me with VBA code..
R Name Dname Rcount Dcount
Ramesh Ganesh 3 2(delete other duplicates keep 1st time appeared ) how to do it by vba..?
thanks for the macros — all very helpful.
thank you for the code. Actually i want to execute the same code in my excel sheet because I need to do the same thing but it didn’t work. Would you help me find out what is wrong? I always receive the same error message “sub or function not defined”.
Trying to use this for deleting multiple columns:
Problem is I keep getting an exception on the colon between A & D. expected list seperator or )
I don’t see the problem, but maybe I’ve just been staring at it too long
I have tried your code and its working for me.
Try this alternative code, this will use the Columns object:
I am creating a template to be used by numerous people for various projects which, depending on the project, a different number of columns will be required.
To help explain, Columns A&B are fixed and I do not want any to be deleted. Columns C-Q have data for them for each country that is within a project. I currently have 15 columns here as this is the max number of countries possible. If someone uses data for a project with only 3 countries, columns C, D and E would display the country name as the header and relevant data underneath, and columns F – Q will just be blank (albeit with formulae within the cell just returning a blank result). I want to use a macro so the person can just press a button and it deletes these excess columns for them.
Is this possible? Not sure if it makes it easier but could get the header to return a certain result rather than leaving blank, e.g. in columns F-Q, using the above example, the header would be ‘DELETE’. Could I then get a macro to search for any columns that show DELETE in the header and delete the entire column?
Thank you in advance!
I want to delete non specific columns to be delete
i have 3 sheets , each sheets contain 100+ columns , in that i require 15 columns only
i want 15 columns & remaining to be deleted in every sheets at a time.
Its urgent , taking more than 15 min for 3 sheets
Am trying to delete over 2000 columns (replacing worksheet not an option). The VBA code is this:
No matter what I do (using ClearContents, Clear, repair spreadhseet, reboot, clear Windows Temp folder), I always get the message: Run-time error ‘1004’: Delete method of range failed.
When I try to break the delete into smaller segments, such as 100 columns at a time, as in:
I get the message after roughly 700 columns.
Am I hitting some sort of internal limitation? Is there some buffer that needs to be reset?
Actually i have 100 columns in my excel sheet.I have to delete all empty columns in the sheet [Here, i don’t know which column number is empty].
please help me to resolve this issue.
Can anyone help me,
I want to delete multiple columns and in many sheets (delete same columns; multiple in all sheets)
Hi , Can someone help me with the below scenario.
I have a column name “COMMENT” in my excel sheet. However the comment column comes 5 times or more than that.
I need to keep the latest comment column and delete the rest other comment columns. I have tried to achieve this by using Range & cell values but the cell values are not static they are getting changed when i export any other document into excel.