Macro that deletes columns

ironsides

Well-known Member
Joined
Aug 12, 2002
Messages
575
Is there a macro that will delete specified columns?

I have a sheet with 26 cols and want to delete cols d, f, k and z.

Thank you
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Turn on the macro recorder, delete those columns, turn off the macro recorder, and you will have your macro.
 
Upvote 0
You can do a simple recorded macro for that which is where I got the following code:

Code:
Sub DFKZ()

    Range("D:D,F:F,K:K,Z:Z").Select
    Range("Z1").Activate
    Selection.Delete Shift:=xlToLeft

End Sub
 
Upvote 0
In a test workbook, sheet1, place the letter of the colum in each cell in row 1, from column A thru column Z.

Copy the following code:

Code:
Sub DeleteColumnsDFKZ()
'
' DeleteColumnsDFKZ Macro
' Macro created 10/11/2006 by Stanley D. Grom, Jr.
'
    Range("D1,F1,K1,Z1").Select
    Range("Z1").Activate
    Selection.EntireColumn.Delete
    Range("A1").Select
End Sub

Press Alt F11, and paste into the VBA Project, Sheet1(Sheet1).

Then run the macro.


Have a great day,
Stan
 
Upvote 0
I want to be able to use the macro to turn off the cols temporarily. save the sheet with a different name and then use the sheet in its original format with its original name.
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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