+ Reply to Thread
Results 1 to 7 of 7

Macro to delete all columns except columns Specified

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,709

    Macro to delete all columns except columns Specified

    I have tried to write code to delete all cols except certain specified cols

    The Cols to be retained are as follows

    "Branch Name", "Title", "Initials", "First Name", "Last Name", "ID Type", "ID Number", "Birth Date", "Gender"



    Please Login or Register  to view this content.


    however when running the code , I get a run time error "Application-defined or object defined error" and code below is highlighted


    Please Login or Register  to view this content.

    it would be appreciated if someone could amend my code

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Macro to delete all columns except columns Specified

    read question wrong
    Last edited by nigelog; 04-29-2019 at 11:35 AM.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,027

    Re: Macro to delete all columns except columns Specified

    How about
    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: Macro to delete all columns except columns Specified

    @nigelog: won't that delete all the columns to be retained?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,709

    Re: Macro to delete all columns except columns Specified

    Thanks for the help


    the macro deletes Col headers containing Branch Name", "Title", "Initials", "First Name", "Last Name", "ID Type", "ID Number", "Birth Date", "Gender

    these columns must remain intact i.e., to be retained and all other cols deleted


    Kindly amend your code accordingly

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,709

    Re: Macro to delete all columns except columns Specified

    Thanks for the help Fluff. Your code works perfectly

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,027

    Re: Macro to delete all columns except columns Specified

    You're welcome & thanks for the feedback

+ 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. Replies: 5
    Last Post: 10-06-2017, 03:59 PM
  2. [SOLVED] Macros - Delete Columns, Cut & Paste Columns then Sorted by Column
    By M12NIX in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-17-2015, 10:49 AM
  3. vb script to find specific names in columns and delete the other columns
    By mac7988 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2015, 09:03 AM
  4. Macro to delete columns
    By arnab0711 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2014, 09:19 AM
  5. Macro to delete some columns
    By boss1982 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-07-2013, 03:10 AM
  6. [SOLVED] Macro to delete columns except selected columns
    By VKR in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2013, 10:01 AM
  7. 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

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