Delete column based on header selection

Eric Carolus

Board Regular
Joined
Sep 17, 2012
Messages
133
Office Version
  1. 2016
Platform
  1. Windows
Hallo All!

I have searched low and high buy could no find what I was looking for.
I have a named (dynamic) range called "Rooms" that contain venues, room numbers (1,2,5, 7) and text (Hall, Lab, etc).

I wish to manually select the Header (e.g. 1, or 2 or Hall), I want VBA to extend the column from the header (selection)
down by 10 rows, delete that the resulting column, and shift all columns to the left.

I thank you in advance.:confused:

Eric
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Do actually mean "down by 10 rows, delete that the resulting column" as in the whole column or do you mean delete the 11 cells or do you mean something else?

Btw, I am not getting the significance of the named range in your question as you are manually selecting the header.
 
Upvote 0
Hi

Yes I mean the header PLUS 10 rows. I guess you are right, we can ignore the named range.

Thanks

Eric
 
Upvote 0
If you mean delete the header + 10 rows then

Code:
Selection.Resize(11).Delete Shift:=xlToLeft

if you mean the 10 rows below the header then

Code:
Selection.Offset(1, 0).Resize(10).Delete Shift:=xlToLeft
 
Upvote 0
Hallo MARK858

Thank you for the advice , but I could not make it work.

I am now going to include the workbook.
Its has two sheets (Sheet1 & AddRooms) and three buttons (AddRooms, Delete Rooms & Specific Removal) on Sheet1.
AddRooms & Delete Rooms Add rooms (to the Last column) and Delete rooms (remove the last Column) respectively.

I wish to change the Delete rooms (instead of deleting the Last room added) to the DELETING the room that I SELECTED in the HEADER (that could be any room).

I had been at this almost all day, too no avail.

Thanks you to all of you in advance.

Here is the link to the workbook: https://www.dropbox.com/s/qy1gduz7bijiyq3/insert a column.xlsm?dl=0

Eric
 
Upvote 0
When I put the code as posted in a regular module, unprotect your worksheet, select the header and run the code it deletes the column fine.
 
Last edited:
Upvote 0
Hi MARK858!

And you are sooooo right! It works just fine.

My problem? forgot to Unprotect the sheet!

Thanks once again!

I really appreciate it.

Eric
 
Upvote 0
Happy you got it sorted. Btw, as your data is 10 rows including the header it should be...

Code:
Worksheets("Sheet1").Unprotect "myPassword"
Selection.Resize([B][COLOR="#FF0000"]10[/COLOR][/B]).Delete Shift:=xlToLeft
Worksheets("Sheet1").Protect "myPassword"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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