+ Reply to Thread
Results 1 to 15 of 15

Copy a Row and Paste It

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Copy a Row and Paste It

    Hi, I need to copy a row from a worksheet and paste it into the next available row on another worksheet in the same workbook. There are a only going to be a maximum of 100 records and the user can do the whole lot at the same time. I need this function so that late comers can be added.

    I was going to put a button on every row i.e 100 buttons but Im not sure if thats the way to go.

    Help and advise required please.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    I'd suggest you just need a routine that will copy the currently selected row and paste that to the second sheet.

    Attach that to a button.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    Could you post an example please?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    Please Login or Register  to view this content.
    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Copy a Row and Paste It

    Copy.xlsm
    here is attachment

  6. #6
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    Hi, sorry for taking so long to reply. This is going the right way, I have attached a spreadsheet to help explain what I am after.

    I want to select a row, then click the update button, if 'Y' is in Set 1 then it gets put into the first available row (rememebering there are three header rows) in Sheet Set 1, if 'Y' is in Set 2 then it gets put into the first available row in Sheet Set 2, if 'Y' is found to be in Set 1 and Set 2 then it goes into the first available slot on Sheet Set 1 and Sheet Set 2Only the first three colums need to be copied!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    Could really use a bit of help on this if possible, many thanks.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    If it takes you two days to respond to an initial reply, why would you expect an immediate response when you do come back?

    Attach this to your button:

    Please Login or Register  to view this content.

    Regards, TMS

  9. #9
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    I know I set this as solved but I have a related question. the Spreadsheet that I posted was clearly a very simplified version. Could you explain at what point in the code it knows that it should paste the Row 11 (thats Name 10) for example into into sheet 'Set 2'.

    Im just trying to understand.

    Many thanks

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    acRow is used to store the Active Cell's row number.

    This is used in the next line to determine which column has "Y" in it.

    And that, in turn is used to find the sheet number in the top row.

    Finally, acRow and acSheet are used in the copy statement.

    There's no error handling so it may well fail if it doesn't find a "Y" or the sheet doesn't exist.

    Thanks for the rep.

    Regards, TMS

  11. #11
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    So does that mean that the Sheet Name must be the same as the Colomn Name i.e. Set 1, Set 2 etc?
    Last edited by Cutter; 09-18-2012 at 04:49 PM. Reason: Removed whole post quote

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    Yes ... as in your example. How else would you work out which sheet to copy the row to?

    If you have some fixed relationship between the column header and the sheet name, you could incorporate that. Or you could have a look up table with column names and sheet names.

    I'm not sure why you're asking the question. Do your column headers not match the sheet names? If that's the case, how would you hope to determine which sheet is required to be updated?

    Regards, TMS

  13. #13
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    Yes they do match, the only difference is, is that the column headers are on Row 5 of the first sheet, I was just trying to understand which number I should change to make it understand that Row 5 held the Colomn headers!

    I should add that I have figured this bit out.

    What if I had Y in more than one set, this is a potential problem for me.
    Last edited by Cutter; 09-18-2012 at 04:49 PM. Reason: Removed whole post quote

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Copy a Row and Paste It

    Please Login or Register  to view this content.
    That's a different question and, yes it is. Rather than using MATCH to find the relevant header, you'd need to loop through the columns for the active row and repeat the copy for each occurrence of the flag (Y).

    Not that difficult to do, just not the question you asked or provided sample data for

  15. #15
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Copy a Row and Paste It

    Many thanks for your help, please see my new thread!

+ 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