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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,273
Turn on the macro recorder, delete those columns, turn off the macro recorder, and you will have your macro.
 

jmckeone

Well-known Member
Joined
Jun 3, 2006
Messages
550
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
 
Joined
Jul 30, 2006
Messages
3,656
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
 

ironsides

Well-known Member
Joined
Aug 12, 2002
Messages
575
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.
 

Forum statistics

Threads
1,171,062
Messages
5,873,555
Members
432,983
Latest member
sam97

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
Top