+ Reply to Thread
Results 1 to 12 of 12

VBA to find and delete columns.

  1. #1
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    VBA to find and delete columns.

    Hi,
    I have sheet "Working". In this I have a column with Heading New Sheet1, New Sheet2, New Sheet3, New Sheet4, New Sheet5 and New Sheet6.

    I need a macro to find above Heading New Sheet1, New Sheet2, New Sheet3, New Sheet4, New Sheet5 and New Sheet6 in Row number 1 and if it exist then delete those columns.

    And find last filled column in the same sheet and add new 6 columns with same heading New Sheet1, New Sheet2, New Sheet3, New Sheet4, New Sheet5 and New Sheet6

    The Column heading format should be in Red font.bold and backgroung yellow colour
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to find and delete columns.

    So you don't actually want to delete the column labels, it appears you just want to clear anything that's in those columns. In which case

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to find and delete columns.

    Somehow.... But not exactly.

    Because these columns may anywhere in the the sheet, Between any columns or first last or in a MID. Also wanted clear contents in existing columns. Hence Wanted to find and delete these columns and insert new columns (one after one) after a last column,

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: VBA to find and delete columns.

    Try this:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to find and delete columns.

    hi,
    Please check the attachment the code is not running
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA to find and delete columns.

    Does this macro do what you want...
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to find and delete columns.

    Hi, I have given Column Heading Starting with "New Sheet" just for an example.

    Actuall I have 10 columns with below headings. And more can be added / deleted in future. Can you provide your accordingly.


    No_Annualised_Claims
    No_Annualised_Claims_With_IBNR
    Annualised_Claim_Amount
    Annualised_Claim_Amount_With_IBNR
    Age_Band_1
    Age_Band_2
    Age_Band_3
    Age_Band_4
    Age_Band_5
    Amount_Band

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA to find and delete columns.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to find and delete columns.

    Dear Jindon,
    I tried it on sample file. It is not deleting all existing column with same heading.
    at final result only 10 columns to be there after running the code. that too it start from the last column
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA to find and delete columns.

    Add/remove the item in myList.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to find and delete columns.

    thats perfect

  12. #12
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA to find and delete columns.

    Quote Originally Posted by saravanan1981 View Post
    No_Annualised_Claims
    No_Annualised_Claims_With_IBNR
    Annualised_Claim_Amount
    Annualised_Claim_Amount_With_IBNR
    Age_Band_1
    Age_Band_2
    Age_Band_3
    Age_Band_4
    Age_Band_5
    Amount_Band
    Question... are the above headers the only headers that have red bold font in a yellow filled cell? If so, here is another macro that you can consider...
    Please Login or Register  to view this content.
    Note: If those headers are the only header with yellow fill, then you can remove the two lines of code I highlighted in red above.

+ 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. 2 columns find dublicates and delete them with macro
    By pollux7 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 04-17-2018, 06:52 PM
  2. 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
  3. find matching row data in two columns, delete the second row.
    By master-richie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2015, 11:35 AM
  4. [SOLVED] Find all - delete BUT the cell [x] columns to the right
    By mallymcl in forum Excel General
    Replies: 5
    Last Post: 02-07-2014, 02:13 AM
  5. [SOLVED] More efficient way to find and delete columns
    By agentblue in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-30-2013, 11:47 AM
  6. Find columns and delete them
    By robertguy in forum Excel General
    Replies: 0
    Last Post: 08-09-2012, 10:54 AM
  7. Find empty columns, rows and delete
    By ebe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2010, 10:00 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