+ Reply to Thread
Results 1 to 5 of 5

Macro to delete all columns except specified headers

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Macro to delete all columns except specified headers

    Hey there everyone,

    First post on the forum, have been grabbing info here for awhile. Feel free to blow me up when I don't follow the SOP.

    I am trying to create a macro that will delete all columns aside from those specified. They must be labeled by the actual column header as data imports can vary greatly. Columns I would like to keep, based on header name are: Word , Pay, Cost, Volume, Rank, & Type

    I really have searched the forum high and low also all over google. Everything is detailed on deleting rows or deleting columns by specifying header to be deleted (not what I want to achieve).

    Thank you.
    Last edited by macattackr; 01-27-2012 at 10:33 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro to delete all columns except specified headers

    Hi macattackr and welcome to the forum.
    Try this code in the attached sample file.
    Please Login or Register  to view this content.
    Note - LastCol looks in Row 1 for your column headers.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    01-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to delete all columns except specified headers

    Hey Marvin that worked great....thank you...i will be submitting another question shortly! starting to learn and pick it up

  4. #4
    Registered User
    Join Date
    03-28-2013
    Location
    Magnolia, TX
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Macro to delete all columns except specified headers

    Wow thanks, I am an accountant and my manager just asked me to do the same exact thing. This worked perfect!

  5. #5
    Registered User
    Join Date
    05-07-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to delete all columns except specified headers

    hi all its my first post, so please bare with me

    i used the marco you posted and it did the job! Thank you

    what i also need to do is make the data which remains into a table without manually doing it. is there anything i could add to the marco that would convert it into a table once it deletes the irrelevant columns?

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to delete all columns except specified headers

    milkfloat,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1