+ Reply to Thread
Results 1 to 12 of 12

Excel macro to delete column

  1. #1
    Registered User
    Join Date
    12-02-2014
    Location
    Pune
    MS-Off Ver
    Office 13
    Posts
    5

    Excel macro to delete column

    Hi,

    I have certain number of columns with names starting from A, B, C ... to Z. Through an external program, I get a comma separated list of column names as "A,B,E,G". Now my task is to delete all the columns from A to Z except for the once occurring in the list i.e., A,B,E,G, in this case. How can I do this?

    Thanks for the help in advance.

    Regards,
    Omkar.

  2. #2
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: Excel macro to delete column

    Hi ... Welcome....
    Can you post your data... it would be easy to provide you solution...

    Click Go advanced and click on paper clip icon and browse and upload the file.....

  3. #3
    Registered User
    Join Date
    12-02-2014
    Location
    Pune
    MS-Off Ver
    Office 13
    Posts
    5

    Re: Excel macro to delete column

    Hi naveenmarapaka,

    Please find the attached herewith the file. The columns are "A, B, C, D, E, F, G, H, I, J". Here in cell "N1" of the sheet I have a list "A,B,E,I". Now I have to delete all the columns of the given table except "A,B,E,I". Thus the columns to be deleted will be "C,D,F,G,H,J".
    Please let me know if you need any further information.
    Thanks!

    Regards,
    Omkar.
    Attached Files Attached Files

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel macro to delete column

    Hi Omkar

    Welcome to the Forum!!!

    Will there always be only 10 Columns of Data?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Excel macro to delete column

    You information concerning columns to keep is in column "N" and you want to search the columns to delete from A to Z ...?
    - Battle without fear gives no glory - Just try

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel macro to delete column

    Hi Omkar

    This Code in the attached appears to work as expected on your Sample File. I believe you'll need to address PCI's question regarding your Live File.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: Excel macro to delete column

    Try this as well...

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-02-2014
    Location
    Pune
    MS-Off Ver
    Office 13
    Posts
    5

    Re: Excel macro to delete column

    Thanks naveenmarapaka, jaslake, PCI for spending time on my doubt.

    This is working fine now. You guys rock

    Thanks once again !!!
    Last edited by omkark2; 12-09-2014 at 12:43 AM.

  9. #9
    Registered User
    Join Date
    12-02-2014
    Location
    Pune
    MS-Off Ver
    Office 13
    Posts
    5

    Re: Excel macro to delete column

    Thanks naveenmarapaka, jaslake, PCI for spending time on my doubt.
    This is working fine. You guys rock.

    Thanks once again !!!

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel macro to delete column

    You're welcome...glad I could help.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    If this resolves your issue please mark your Thread as SOLVED.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  11. #11
    Registered User
    Join Date
    12-02-2014
    Location
    Pune
    MS-Off Ver
    Office 13
    Posts
    5

    Re: Excel macro to delete column

    Oops Sorry but this did not solve my problem. I checked it today. So it is keeping the Excel columns mentioned in cell "N1" of the sheet and deleting the remaining columns. However, I want the columns headers specified in the table to deleted. Like if the cell "N1" has "A,E,B,I" and want to delete all other columns except these from MY table and not the column names specified by Excel. For better understanding, I am uploading a new file. Here I want only Name and Phone to be the final columns. Please refer the "Desired Output" sheet in the file to know the exact requirement.
    Attached Files Attached Files
    Last edited by omkark2; 12-11-2014 at 06:55 AM.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel macro to delete column

    Hi Omkar

    Your explanation is a bit confusing but this Code in the attached achieves your described Desired Output in your Sample File. Ctrl + x will fire the Code.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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 count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  2. Macro to delete column in front of yellow highlighted column
    By Getsuko Teng in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2012, 02:30 PM
  3. Run Macro Automatically When delete row , changes cell,delete column
    By elevisse in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2012, 07:42 AM
  4. 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
  5. Macro to delete first row and insert column after a certain number of column
    By arnab0711 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2011, 08:36 PM

Tags for this Thread

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