+ 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
    Posts
    465

    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 Expert
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    4,803

    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
    258

    Re: Delete unwanted columns and only keeping known name columns

    or:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    4,803

    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
    258

    Re: Delete unwanted columns and only keeping known name columns

    true, but what is the chance

  6. #6
    Forum Expert
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    4,803

    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
    3,366

    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
    Posts
    465

    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 Expert
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    4,803

    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)

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