+ Reply to Thread
Results 1 to 3 of 3

Copy columns to new workbook with matched headers, then save new workbook as a text file.

  1. #1
    Registered User
    Join Date
    12-10-2017
    Location
    Netherland
    MS-Off Ver
    2016
    Posts
    19

    Copy columns to new workbook with matched headers, then save new workbook as a text file.

    Hi everyone, I'm still new to VBA so please forgive me if there is any mistake describing the situation.
    So basically I want to create a macro that copy columns from a Sheet, these columns have to match headers in another Sheet, to a new workbook.

    Workbook 1 has Sheet Settings (Sheet 1) and Sheet Inputfile (Sheet 2).
    Sheet Inputfile has data with columns headers for each columns.
    Sheet Settings has Column Name column, user will enter the columns that they want to copy in this column (the columns name are from Sheet Inputfile).
    I want to create a macro that copy columns from Sheet Inputfile to a new Workbook, these columns's headers have to matched the headers in the Output line (at row 10 starting at Cells "E10") in Sheet Settings. The order of the columns in the new Workbook has to be the same in the Output line.
    After succesfully copy the wanted columns to a new workbook, I keep getting this problem,the macro always sees column "Procedure" as "Test Name". And it's still working fine for other columns.
    For example: I want to copy columns: "Procedure", "Key", "Test Name" and "A time [min]", when it copies to a new Workbook, the Workbook shows columns "Test Name", "Key", "Test Name" and "A time [min]".

    Can someone help me to find what the error is here? You can see the attached file for more details.
    Also how can I save the new Workbook as a text file in the same directory with the Workbook?

    Any help would be appreciated.
    Thank you.
    Attached Files Attached Files
    Last edited by haitran; 12-17-2017 at 09:57 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy columns to new workbook with matched headers, then save new workbook as a text fi

    My take on this.

    1) just make sure the columns listed in A are in the correct order, no need adding a second control that does the same thing.
    2) The combobox seems unnecessary. Just type the output filename in that cell.
    3) A formula in E1 can spot the header row for you.
    4) No idea what E2 is for.

    Here's my result and it's working:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-10-2017
    Location
    Netherland
    MS-Off Ver
    2016
    Posts
    19

    Re: Copy columns to new workbook with matched headers, then save new workbook as a text fi

    Thank you very much for the help :D

+ 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. Copy columns to a new workbook if the headers row matched
    By haitran in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-13-2017, 06:32 PM
  2. Want to open file, copy filtered data to new workbook and at save as new file
    By satishdu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-25-2014, 12:39 PM
  3. Copy, edit and save workbook to same location as source data file, not macro file.
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 09:01 AM
  4. Replies: 3
    Last Post: 07-11-2013, 03:01 AM
  5. Replies: 5
    Last Post: 03-21-2013, 07:34 AM
  6. Search multiple workbook headers and copy column entries to another workbook
    By R3n3gad3-XtC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2012, 12:47 AM
  7. Copy specific columns and save into another workbook
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2008, 04:02 PM

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