+ Reply to Thread
Results 1 to 9 of 9

Delete unwanted columns and only keeping known name columns

  1. #1
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    474

    Question Delete unwanted columns and only keeping known name columns

    Hi,

    Can anyone please advise me of the VBA code required to search all the headings (in row 1) in a worksheet for specific headings e.g. Code, Date, Name etc and delete any columns that do no match these names, and also delete any columns if they are blank i.e. no text in the heading row i.e. in row 1

    (N.B. the names of the columns to keep will be stored within the VBA code)


    Any assistance would be greatly appreciated


    Many thanks in advance

    Regards


    Rob
    Rob

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

    Re: Delete unwanted columns and only keeping known name columns

    How about
    Please Login or Register  to view this content.
    Change values in red to suit

  3. #3
    Forum Contributor
    Join Date
    05-12-2018
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    266

    Re: Delete unwanted columns and only keeping known name columns

    or:

    Please Login or Register  to view this content.

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

    Re: Delete unwanted columns and only keeping known name columns

    SjonR
    The problem with that is that it will also keep columns such as "Post", "code", "strict" etc if they exist.

  5. #5
    Forum Contributor
    Join Date
    05-12-2018
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    266

    Re: Delete unwanted columns and only keeping known name columns

    true, but what is the chance

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

    Re: Delete unwanted columns and only keeping known name columns

    Without knowing the OP's data, impossible to say.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    Another way :

    PHP Code: 
    Sub Demo1()
        Const 
    "IF(ISNA(MATCH(#,{""Code"",""Date"",""Name""}, 0)),ADDRESS(1,COLUMN(#)))"
        
    Join(Filter(Evaluate(Replace(F"#"ActiveSheet.UsedRange.Rows(1).Address)), FalseFalse), ",")
        If 
    "" Then Range(V).EntireColumn.Delete
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-14-2018 at 12:08 AM. Reason: optimization …

  8. #8
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    474

    Re: Delete unwanted columns and only keeping known name columns

    Fluff13 & SjonR & Marc L

    Many thanks for all your help and assistance it is very much appreciated and with ayour help I have now resolved my problem


    Thanks Again


    Regards


    Rob

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

    Re: Delete unwanted columns and only keeping known name columns

    Glad we could help & 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: 4
    Last Post: 08-02-2018, 07:13 PM
  2. [SOLVED] automatically extend columns while keeping a minimum width on specific columns
    By enhydra in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2017, 10:13 PM
  3. [SOLVED] A Macro to Delete Unwanted Columns
    By newbieexceldude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-25-2016, 10:36 PM
  4. need to delete unwanted similar columns across multiple workbooks in vba excel
    By sreekanth.buddha in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2016, 08:25 AM
  5. Replies: 0
    Last Post: 08-02-2012, 10:46 PM
  6. Macro to loop through all sheets and delete unwanted columns
    By LemonTwist in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2009, 12:03 PM
  7. Delete unwanted columns
    By stevekirk in forum Excel General
    Replies: 6
    Last Post: 09-24-2006, 08:52 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