Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Delete All Columns Except

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J.W. Aldridge - 28 Feb 2007 23:05 GMT
Looking to create a macro that will erase all columns except where the
first cell (row a) contains the name:

Eggs
Cheese
Salad
Pizza
Dave Peterson - 28 Feb 2007 23:20 GMT
Row 1?????

Option Explicit
sub testme()
 dim iCol as long
 with activesheet
    for icol = .cells.specialcells(xlcelltypelastcell).column to 1 step -1
       select case lcase(.cells(1,icol))
          case is = "eggs","cheese","salad","pizza"
             'do nothing, keep it
          case else
             .columns(icol).delete
       end select
    next icol
 end with
end sub

This assumes that there's nothing else in the cell except those names.

> Looking to create a macro that will erase all columns except where the
> first cell (row a) contains the name:
[quoted text clipped - 3 lines]
> Salad
> Pizza

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.