I am trying to delete multiple columns in VBA for Excel. I downloaded data from the Illinois Statistical analysis center about drug arrest. http://www.icjia.org/public/sac/index.cfm?metasection=forms&metapage=rawMetadata&k=170
Each of the columns I want to delete are 3 columns apart from each other.
For example:
Adams County Illinois Champaign County Illinois Estimate |percent | Percent Margin of Error |Estimate Margin| Estimate| Percent | Percent Margin of Error
D|E|F|G|H|I|J
I just want to delete all the columns the say Percent Margin of Error
Here is my macro:
Sub deleteCol()
Columns("H,J").Delete
End Sub
I keep getting an error:
Run-time 13: type mismatch
Any suggestions?
Explained VBA Code to Delete Multiple Columns: '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.
Right-click in a table cell, row, or column you want to delete. On the Mini toolbar, click Delete. Choose Delete Cells, Delete Columns, or Delete Rows.
You were just missing the second half of the column statement telling it to remove the entire column, since most normal Ranges start with a Column Letter, it was looking for a number and didn't get one. The ":" gets the whole column, or row.
I think what you were looking for in your Range was this:
Range("C:C,F:F,I:I,L:L,O:O,R:R").Delete
Just change the column letters to match your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With