delete columns

hendrikbez

Board Regular
Joined
Dec 13, 2013
Messages
94
Office Version
  1. 2021
Platform
  1. Windows
I am trying to delete columns from one of my sheets, but cannot get it to delete, I have tried with sheet6 and insert(sheet name)

I have put a button on sheet5 t5o delete columns on sheet6(Insert), but it is not working

VBA Code:
Sub Del_columns()
 Dim sourceSheet As Worksheet
 Set sourceSheet = Sheet6
 sourceSheet.Columns("H:Z").EntireColumn.Delete
 End Sub

Code:
Sub Del_columns()
 Dim sourceSheet As Worksheet
 Set sourceSheet = Insert
 sourceSheet.Columns("H:Z").EntireColumn.Delete
 End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this:
VBA Code:
Sub Delete_Columns()
'Modified  11/22/2019  3:22:16 AM  EST
 Sheets("Insert").Columns("H:Z").Delete
End Sub
 
Upvote 0
Thank you, but it is still not working

VBA Code:
Sub Del_columns()
 'Dim sourceSheet As Worksheet
 'Set sourceSheet = Sheet6
 'sourceSheet.Columns("H:Z").EntireColumn.Delete
  'Modified  11/22/2019  3:22:16 AM  EST
 
 
 Sheets("Insert").Columns("H:Z").Delete
 End Sub
 
Upvote 0
Will this work if there is info on some rows. if I have ifo on row 4H, will this also delete it.
 
Upvote 0
Please define "Doesn't work"
Do you get error messages, does it delete columns on the wrong, or what?
 
Upvote 0
I have the code in module1
I have the button on sheet "all"
I want to delete columns with info in sheet "insert"
When I click on the button, nothing is happening at all.
 
Upvote 0
Apologies if this sounds like a stupid/insulting question, but have you assigned that macro to the button?
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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