+ Reply to Thread
Results 1 to 8 of 8

Copy columns of different headers

  1. #1
    Forum Contributor
    Join Date
    04-22-2013
    Location
    Philippines
    MS-Off Ver
    Office 365, Excel 2016
    Posts
    146

    Lightbulb Copy columns of different headers

    Hi,

    I am looking for a fastest code that will do the flow below. I have 2 sheets in a workbook wtih "old" and "new" sheet. The old sheet has 100+ columns and thousands of data. The new sheet is where all the needed data from the old sheet should be copied. The new sheet has already have the headers (Row 1).

    The tool flows like this:
    1] get the value in sheet new A1
    2] find the value in sheet old columns 1-100
    3] when the value is found, copy the entire column from sheet old to sheet new of the same header
    4] when the value is not found, go to next value in sheet new B2
    5] and repeat step 3 or 4 until all headers in sheet new are populated


    I am not yet expert to use arrays and for loops so I will be needing a help to code this.

    Thank you.

  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: Copy columns of different headers

    Hi,

    Seems like a simple case for Inspector Data Filter.

    Create a helper column in the old sheet and use an =MATCH(() function to identify those rows in the old sheet which have a corresponding reference in the new sheet. e.g.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Now either use an Autofilter on the helper column for the word Copy the select all the filtered rows and copy and paste them to the new sheet. Alternatively use the Advanced Data Filter.
    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
    04-22-2013
    Location
    Philippines
    MS-Off Ver
    Office 365, Excel 2016
    Posts
    146

    Re: Copy columns of different headers

    Hi Richard,

    I actually need a whole code for this.

    Thanks.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy columns of different headers

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    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: Copy columns of different headers

    Quote Originally Posted by SBBmaster09 View Post
    Hi Richard,

    I actually need a whole code for this.

    Thanks.
    Are you able to upload the workbook so we can understand the layout and see the request in context?

  6. #6
    Forum Contributor
    Join Date
    04-22-2013
    Location
    Philippines
    MS-Off Ver
    Office 365, Excel 2016
    Posts
    146

    Re: Copy columns of different headers

    Hi John,

    It exactly does the code I need. Your genius.

    Thanks much for this. Really appreciate it.



    Best Regards,
    Sarah

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy columns of different headers

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rules and mark this thread as SOLVED.

  8. #8
    Forum Contributor
    Join Date
    04-22-2013
    Location
    Philippines
    MS-Off Ver
    Office 365, Excel 2016
    Posts
    146

    Re: Copy columns of different headers

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Please Login or Register  to view this content.
    How can I use this code with two different files? The old sheet is workbook 1 and new sheet is workbook 2? How can I modify the code? Thanks.

+ 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 and paste columns based on column headers
    By patwary786 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2015, 11:43 PM
  2. Copy multiple columns by checking headers in each file
    By VidyaVallaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2014, 04:02 PM
  3. macro to add columns after existing columns and copy/paste headers and formulas
    By rhybeka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 02:35 PM
  4. [SOLVED] Copy pasting columns based on headers
    By krash297 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2013, 02:13 PM
  5. Summary - Copy the columns based on column headers
    By rafiomeon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2012, 10:32 AM
  6. Excel 2007 : Macro to copy columns based headers
    By rls1316 in forum Excel General
    Replies: 2
    Last Post: 04-25-2011, 10:22 PM
  7. Macro for comparing headers and copy/pasting respective columns
    By Sarushka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2009, 08:48 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