deleting column automatically

ehsas69

Board Regular
Joined
Jan 10, 2004
Messages
221
Can I have formula or macro to automatically assigned to a button on the worksheet to delete the column A-M from worksheet 2.

Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
paste the middle line into the code for the button

Sub deleterange()
Range("A:M").EntireColumn.Delete
End Sub

this will just work on the active worksheet though.
 
Upvote 0
maybe this would be better to make sure you activate the right sheet.

Sub deleterange()
Sheet1.Range("A:M").EntireColumn.Delete
End Sub
 
Upvote 0
Do you want to clear the data leaving columns A-M blank and leaving column N the same or do you want do delete the columns so that column N becomes column A?
 
Upvote 0
In all fairness, your original post did request how to delete the columns--not the contents.

To remove the data from the columns, use ClearContents:

Sheets("Sheet2").Columns("A:M").ClearContents
 
Upvote 0

Forum statistics

Threads
1,219,161
Messages
6,146,657
Members
450,706
Latest member
LGVBPP

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