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LC:LD,LF:LG,LI:LJ, _
LL:LM,LO:LP,LR:LS,LU:LU,LW:LW,LY:LY,MA:MA,MC:MC,ME:ME,MG:MG,MI:MI,MK:MK,MM:MM,MO:MO,MQ:MQ,MS:MS,MU:MU,MW:MW,MY:MY,NA:NA,NC:NC,NE:NE,NG:NG, _

NI:NI,NK:NK,NM:NM,NO:NO,NQ:NQ,NS:NS,NT:NT").Select
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This probably will do it although it's quite clunky:

Code:
Sub DeleteAll()

Set rng1 = Range("B:B,C:C,E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y,AA:AA,AC:AC,AE:AE,AG:AG,AI:AI,AK:AK,AM:AM,AO:AO,AQ:AQ,AS:AS,AU:AU,AW:AW,AY:AY")
Set rng2 = Range("BA:BA,BC:BC,BE:BE,BG:BG,BI:BI,BK:BK,BM:BM,BO:BO,BQ:BQ,BS:BS,BU:BU,BW:BW,BY:BY,CA:CA,CC:CC,CE:CE,CG:CG,CI:CI,CK:CK,CM:CM,CO:CO")
Set rng3 = Range("CQ:CQ,CS:CS,CU:CU,CW:CW,CY:CY,DA:DA,DC:DC,DE:DE,DG:DG,DI:DI,DK:DK,DM:DM,DO:DO,DQ:DQ,DS:DS,DU:DU,DW:DW,DY:DY,EA:EA,EC:EC,EE:EE")
Set rng4 = Range("EG:EG,EI:EI,EK:EK,EM:EM,EO:EO,EQ:EQ,ES:ES,EU:EU,EW:EW,EY:EY,FA:FA,FC:FC,FE:FE,FG:FG,FI:FI,FK:FK,FM:FM,FO:FO,FQ:FQ,FS:FS,FU:FU,FW:FW,FY:FY")
Set rng5 = Range("GA:GA,GC:GC,GE:GE,GG:GG,GI:GI,GK:GK,GM:GM,GO:GO,GQ:GQ,GS:GS,GU:GU,GW:GW,GY:GY,HA:HA,HC:HC,HE:HE,HG:HG,HI:HI,HK:HK,HM:HM,HO:HO,HQ:HQ,HS:HS")
Set rng6 = Range("HU:HU,HW:HW,HY:HY,IA:IA,IC:IC,IE:IE,IG:IG,II:II,IK:IK,IM:IM,IO:IO,IQ:IQ,IS:IS,IU:IU,IW:IW,IY:IY,JA:JA,JC:JC,JE:JE,JG:JG,JI:JI,JK:JK,JM:JM")
Set rng7 = Range("JO:JO,JQ:JQ,JS:JS,JU:JU,JW:JW,JY:JY,KA:KA,KC:KC,KE:KE,KG:KG,KI:KI,KK:KK,KM:KM,KO:KO,KQ:KQ,KS:KS,KU:KU,KW:KW,KY:KY,LA:LA,LC:LD,LF:LG,LI:LJ")
Set rng8 = Range("LL:LM,LO:LP,LR:LS,LU:LU,LW:LW,LY:LY,MA:MA,MC:MC,ME:ME,MG:MG,MI:MI,MK:MK,MM:MM,MO:MO,MQ:MQ,MS:MS,MU:MU,MW:MW,MY:MY,NA:NA,NC:NC,NE:NE,NG:NG")
Set rng9 = Range("NI:NI ,NK:NK ,NM:NM ,NO:NO , NQ:NQ, NS:NS , NT:NT")

rng1.EntireColumn.Delete
rng2.EntireColumn.Delete
rng3.EntireColumn.Delete
rng4.EntireColumn.Delete
rng5.EntireColumn.Delete
rng6.EntireColumn.Delete
rng7.EntireColumn.Delete
rng8.EntireColumn.Delete
rng9.EntireColumn.Delete

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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