Deleteing unwanted colums

cuetipper

Board Regular
Joined
Nov 9, 2018
Messages
67
I have a report that has many columns, A - CC. There are ten columns I need and want to delete the rest.
Is there a way to specify the original range and delete them all Except those in a list?

-Cue
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I have a report that has many columns, A - CC. There are ten columns I need and want to delete the rest.
Is there a way to specify the original range and delete them all Except those in a list?

-Cue

Try this:
I assumed there are no blank cell in row 1 columns A - CC.
Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1077802b[B]()[/B]
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1077802-deleteing-unwanted-colums.html[/COLOR][/I]
[B][COLOR=Royalblue]Dim[/COLOR][/B] c [B][COLOR=Royalblue]As[/COLOR][/B] Range[B],[/B] x[B],[/B] ary[B],[/B] flag [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Boolean[/COLOR][/B]
 ary [B]=[/B] Split[B]([/B][COLOR=brown]"A,C,F,AB,BA,BF,BN,BS,CA,CB"[/COLOR][B],[/B] [COLOR=brown]","[/COLOR][B])[/B] [I][COLOR=seagreen]'list of columns[/COLOR][/I]
 
 [B][COLOR=Royalblue]For[/COLOR][/B] [B][COLOR=Royalblue]Each[/COLOR][/B] c [B][COLOR=Royalblue]In[/COLOR][/B] Range[B]([/B][COLOR=brown]"A1:CC1"[/COLOR][B])[/B]
        flag [B]=[/B] [B][COLOR=Royalblue]False[/COLOR][/B]
    [B][COLOR=Royalblue]For[/COLOR][/B] [B][COLOR=Royalblue]Each[/COLOR][/B] x [B][COLOR=Royalblue]In[/COLOR][/B] ary
        [B][COLOR=Royalblue]If[/COLOR][/B] c.Column [B]=[/B] Columns[B]([/B]x[B]).[/B]Column [B][COLOR=Royalblue]Then[/COLOR][/B] flag [B]=[/B] [B][COLOR=Royalblue]True[/COLOR][/B][B]:[/B] [B][COLOR=Royalblue]Exit[/COLOR][/B] [B][COLOR=Royalblue]For[/COLOR][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
        [B][COLOR=Royalblue]If[/COLOR][/B] flag [B]=[/B] [B][COLOR=Royalblue]False[/COLOR][/B] [B][COLOR=Royalblue]Then[/COLOR][/B] c [B]=[/B] [COLOR=brown]""[/COLOR]
 [B][COLOR=Royalblue]Next[/COLOR][/B]
 
 Range[B]([/B][COLOR=brown]"A1:CC1"[/COLOR][B]).[/B]SpecialCells[B]([/B]xlCellTypeBlanks[B]).[/B]EntireColumn.Delete
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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