Delete Multiple Columns

MattC00

New Member
Joined
Apr 29, 2011
Messages
6
Hello all, I've no doubt this is so simple it's elsewhere in the forum but I've spent 90 minutes trying to find it and all my searches return something much complicated that I need, understand, or am ready for!!

Basically, I have a direct export setup from a database that comes off with Columns A - IH, and contains a load of rubbish that I don't need for my purposes.

What I'd like is a Macro that just says "delete columns A, C, E, Z, AA, DR" etc, so I can just trim the export down to the data that I actually need.

I have tried something like

Columns("B").Delete
Columns("D:G").Delete
Columns("J").Delete

But that of course recalcualtes, so after it deletes column B, it then starts again and what it now thinks is in Column D was originally in Column E. What I'd like is a macro that does it all based on the "starting point" if that makes sense.

If someone is able to help it would be greatly appreciated! Thanks!

Ps. I can set the macro by "column name" if needs be as they'll always be consistent, but using Column Letter would be preferable.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try

Code:
Sub DelCols()
Range("A1,C1,E1,Z1,AA1,DR1").EntireColumn.Delete
End Sub
 
Upvote 0
Thanks very much chaps really appreciate the assistance, formula's I'm relatively savvy at, Macros are a whole new world to me!

VoG - works perfect thanks again! I'd tried a couple of ways but hadn't accounted for the "1" and using the entirecolumn bit.

gisistek - That would have also worked and have to confess hadn't even thought about it. Having the solution makes it cleaner though thanks VoG :)
 
Upvote 0
Hi Guys,

I'm having a similar problem. I used the code:

Range("C:E;G:K;N:S;W:AJ").EntireColumn.Delete

And

Columns("C:E;G:K;N:S;W:AJ").EntireColumn.Delete

And

Columns("C:E;G:K;N:S;W:AJ").EntireColumn.Select
Selection.EntireColumn.Delete

But there is an error. When they do work however, they don't delete the correct ones. Is there a way to delete the columns at the same time? I think it does the same thing as MattC00's code. It deletes a range of colums then recalculates. "It recalcualtes, so after it deletes column B, it then starts again and what it now thinks is in Column D was originally in Column E".

Please help me understand how to do this.

Thank you :)
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top