Using VBA, delete a column in a range, not entire worksheet

batman37

New Member
Joined
Jul 21, 2007
Messages
14
I have a single row horizontal VBA range that starts with worksheet column F. Using VBA code, I want to delete a selected column from that range only, not from the entire worksheet. The range has been declared (Dim) and Set and used successfully in other code. But so far I have not found any combination of range name, Columns().Delete or EntireColumn().Delete that deletes only the one column from the range and not from the entire sheet. What am I missing? How should the line of code read to accomplish this deletion?

Thanks in advance.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What do you mean:

1) clear content of that range
or
2) clear content of that range, not whole column, but shift cells left

?
 
Upvote 0
What do you mean:

1) clear content of that range
or
2) clear content of that range, not whole column, but shift cells left

?
I don't want to clear any content in the range, except for the specified column to be deleted, with a shift left for everything right of it. Because the range is a single row, the "column" to be deleted happens to be a single cell.
 
Upvote 0
Since you are just deleting a single cell, you can just use:
VBA Code:
    ActiveCell.Delete Shift:=xlToLeft
to delete the selected cell.
 
Upvote 0
Thank you Joe4. That worked beautifully in my application. I suppose that for a multi-row range, I could just For-Next through it by row and apply the same code to each row in turn. When I have some time I'll try it.
 
Upvote 0
Thank you Joe4. That worked beautifully in my application. I suppose that for a multi-row range, I could just For-Next through it by row and apply the same code to each row in turn. When I have some time I'll try it.
No need to do a loop.

If you have selected the cells you wish to delete, just use:
VBA Code:
   Selection.Delete Shift:=xlToLeft
 
Upvote 0
Solution

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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