Deleting entire columns

RichardMGreen

Well-known Member
Joined
Feb 20, 2006
Messages
2,177
Hi all

I've got the following piece of code I've inherited:-
Code:
    Range("G1").Select
    Selection.End(xlToRight).Select
    ActiveCell.Offset(0, 1).Select
    Selection.EntireColumn.Delete
It's part of a much bigger macro and all it does it gets the last used column to the right and deletes the one after it just in case there's some odd characters in it (which messes up a data upload).

I'm fairly certain there's an easier way to do this but I can't get my head around it.

Anyone any pointers?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try

Code:
Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).EntireColumn.Delete
 
Upvote 0
Hi all

It's part of a much bigger macro and all it does it gets the last used column to the right and deletes the one after it just in case there's some odd characters in it (which messes up a data upload).
Presumably you don't mean the one after the last used column to the right, coz if there's one after it then it wouldn't be the last used column.

And what if there aren't any odd characters there, and the "last used column" really is the last used column? Do you still want it deleted?

And is the righthand element in Row1 in the same column as the RH element in other rows? That may make a difference to the approach to deletion.
 
Upvote 0
The last column I want to keep has a header.
Occasionally, the system we use puts odd columns in the column after which is the column I want to delete. Even if it's empty, I can safely delete the column anyway.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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