+ Reply to Thread
Results 1 to 6 of 6

VBA to copy and paste select cells

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    542

    VBA to copy and paste select cells

    Is there a way to copy and paste highlighted cells in an excel? For example, if the total spreadsheet is this:


    Name Age Address DOB
    Chris 18 123 Maple 5/5/1995
    Paul 21 222 High 8/5/1991
    Sara 32 396 Elm 11/18/1970
    Larry 45 522 Walker 4/7/1959

    but only:

    Name Age Address

    Sara 32 396 Elm
    Larry 45 522 Walker


    is there a code that can be used to copy those records if they are selected? Is it possible to have "Name" "Age" "Address" always appear as the column headers on sheet2 cells A1, B1, C1. ? Thanks.

  2. #2
    Registered User
    Join Date
    04-22-2012
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA to copy and paste select cells

    Can you use the macro recorder to copy your steps and use them again next time.

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    542

    Re: VBA to copy and paste select cells

    I can record a macro if the cells are the same everytime, but how do I record a macro to copy selected cells? The cells will be different everytime, the only constant are the column headings "Name" "Age" "Address". Thanks.

  4. #4
    Registered User
    Join Date
    04-22-2012
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA to copy and paste select cells

    Provide a sample with exactly what you want to do. Are you saying you want to highlight a group of cells, run the macro and they will be in the same place on another sheet?

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    542

    Re: VBA to copy and paste select cells

    Sheet1
    A B C D E
    Name Age Address DOB Group
    Chris 18 123 Maple 5/5/1995 Blue
    Paul 21 222 High 8/5/1991 Blue
    Sara 32 396 Elm 11/18/1970 Green

    User macro to copy and paste to Sheet2:

    A B C
    Name Age Group
    Chris 18 Blue
    Sara 32 Green


    Chris 18 Blue
    Sar 32 Green are selected and if possible Name, Age, Group are the column headers on sheet2 but are not selected. Thanks.

  6. #6
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: VBA to copy and paste select cells

    Not sure where you are on this but I have attached a sample of copying cells by colour. You can run the macro and see if this helps.
    If you look at the Testsource sheet you can see the highlighted range. Run the macro and it will copy the rows to the TestDestination sheet. think thats what you were asking? Adjust it to your needs. As there is no sample book to go from
    Attached Files Attached Files

+ 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