+ Reply to Thread
Results 1 to 8 of 8

copy and paste columns based on column headers

  1. #1
    Registered User
    Join Date
    12-11-2014
    Location
    toronto
    MS-Off Ver
    2007
    Posts
    5

    copy and paste columns based on column headers

    I want to copy the 'First Name', 'phone no' and 'date of birth' column from the following spreadsheet (Sheet 1) and paste it in a new sheet call 'New'. My columns are not always in the same order, so copying them by column position doesn't work. Can anyone help me with the code please. Please note that I also have two rows above the column headers which should not be imported to the new sheet.



    This is how my data look like:


    call forward nothing
    Abc hgt
    First Name Last Name Address phone no Zip code Date of Birth
    Natalie Van 10 test street 123456785 11198 3-Jan-14
    Paul Rudloph 22 Another street 258745874 22254 3-Feb-13

    This is how I want my data to be copied in new sheet

    First Name phone no Date of Birth
    Natalie 123456785 3-Jan-14
    Paul 258745874 3-Feb-13






    thank you,
    Attached Files Attached Files
    Last edited by patwary786; 07-23-2015 at 10:35 PM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: copy and paste columns based on column headers

    so you always want to start with row 3 or does that change as well?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    12-11-2014
    Location
    toronto
    MS-Off Ver
    2007
    Posts
    5

    Re: copy and paste columns based on column headers

    Hi humdingaling,
    Yes, I always want to start at row 3 and it never changes.

    Thanks.

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

    Cool Hi ! Try this demonstration !


    B column in New worksheet must be extended …

    PHP Code: 
    Sub Demo()
        
    With Sheet1.Cells(1).CurrentRegion.Rows
            
    .Item("3:" & .Count).AdvancedFilter xlFilterCopy, , Sheet2.[A1:C1]
        
    End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    12-11-2014
    Location
    toronto
    MS-Off Ver
    2007
    Posts
    5

    Re: Hi ! Try this demonstration !

    Hi Marc,
    Thanks you for your help. It's working, but i will not have the same number of columns (but I will have maximum 45 columns) and my column position with the same name sometime changes. Let's say Phone no is sometime in column 8 instead of colunm 4.


    Thanks,

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

    Re: copy and paste columns based on column headers

    Maybe:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: copy and paste columns based on column headers

    @John
    code can be abbreviated
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

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

    Re: Hi ! Try this demonstration !


    Thanks for the rep' !

    Quote Originally Posted by patwary786 View Post
    Let's say Phone no is sometime in column 8 instead of colunm 4.
    Do you see any "column 4" in my code ? But yet it works pretty well ! So no matter with an advanced filter ‼

    Which just matter is the same column name …

+ 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 multiple columns and paste into one column, based on row criteria
    By Miki1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2015, 09:59 AM
  2. 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
  3. [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
  4. [SOLVED] Match, Copy and Paste Column Headers - varying number of columns
    By itcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2013, 10:49 AM
  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. Copy data under specific columns in sheet1 n paste to sheet2 under the same headers
    By ShyamEXcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2012, 02:15 PM
  7. Excel 2007 : Macro to copy columns based headers
    By rls1316 in forum Excel General
    Replies: 2
    Last Post: 04-25-2011, 10:22 PM

Tags for this Thread

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