+ Reply to Thread
Results 1 to 7 of 7

Macro to delete all columns in a workbook based on header name

  1. #1
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    42

    Macro to delete all columns in a workbook based on header name

    Hi

    I am aware this has been asked before but I can't seem to apply any of the solutions to my situation..

    I need a macro that deletes all columns from a workbook that have a certain name "Update" (there may also be another column I want to delete, named "Action required")

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Macro to delete all columns in a workbook based on header name

    Does this work for you?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-10-2014
    Location
    Tallahassee, FL
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: Macro to delete all columns in a workbook based on header name

    Is each column header in row 1 of the worksheet?

    If so:

    Please Login or Register  to view this content.
    Should work, provided you don't ask it to check an empty sheet (that will result in an error).

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Macro to delete all columns in a workbook based on header name

    You can try this code.

    It will work on the sheet that is active when you run the macro or it can be modified to run on other sheets.

    Code assumes your headers are in row 1.

    If you have other header names, or don't want to delete action required, then modify this line in the code, by either adding or deleting header names.

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Last edited by skywriter; 07-14-2015 at 11:15 AM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  5. #5
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    42

    Re: Macro to delete all columns in a workbook based on header name

    Quote Originally Posted by ptmuldoon View Post
    Does this work for you?

    Please Login or Register  to view this content.
    hi, thanks for this but I am having a bit of trouble running this code. I click the play button and nothing happens? Is there some other lines of code I have to add? I have set macro security settings to allow but there must be something else...

  6. #6
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    42

    Re: Macro to delete all columns in a workbook based on header name

    Quote Originally Posted by skywriter View Post
    You can try this code.

    It will work on the sheet that is active when you run the macro or it can be modified to run on other sheets.

    Code assumes your headers are in row 1.

    If you have other header names, or don't want to delete action required, then modify this line in the code, by either adding or deleting header names.

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Thank you, this works How do I modify it so it runs for all the sheets in the workbook? Sorry, bit of a VBA newbie to say the least

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Macro to delete all columns in a workbook based on header name

    You can try this.
    Thanks for the rep. points.

    If your original request is fulfilled please click the Thread Tools drop down box above your first post and choose solved.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to delete columns based on header
    By sfadam in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-25-2015, 05:15 PM
  2. Macro to unlock cells in particular columns based on header value
    By Napa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-17-2013, 05:20 PM
  3. macro to delete blank columns - includes header row
    By bluesea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 12:18 PM
  4. Replies: 2
    Last Post: 10-13-2012, 03:30 AM
  5. Macro to Delete columns in different sheets within a workbook
    By makku in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2012, 09:38 AM
  6. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  7. Delete Columns Based on Header
    By MSmithson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2010, 03:19 AM
  8. Macro to rearrange/add columns based on column header?
    By drdavidge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2006, 09:35 PM

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