+ Reply to Thread
Results 1 to 8 of 8

Copy rows from one sheet based off IDs from another

  1. #1
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Copy rows from one sheet based off IDs from another

    Hi I need help making a macro which helps me copy rows based of IDs from another sheet, and paste them into a new worksheet. The IDs are actually strings of numbers but to make it simple I will explain it like this.

    Sheet 1 just has a list of names: Mark, Mike, Michelle, Monica, Brian, Peter, Sally all in the first column (also has other data in the rows but just ignore these)
    Sheet 2 has a huge list of names, but also has attributes about them for the other columns in the same row (for ex: height, weight, IQ, etc.)
    Sheet 3 has nothing as of yet, but in the end I want it to include the rows in sheet 2 that match names in sheet 1

    So if sheet 1 has the name Mike, I want the script to go through sheet 2 and find where mike is listed, copy the whole row, and paste it into sheet 3.

    Could anyone help me do this? Thanks so much!!

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Copy rows from one sheet based off IDs from another

    excelforum123,

    Can you post your workbook, or a sample workbook with the correct structure (cells, rows, columns), and, sensitive data scrubbed/removed/changed?

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Copy rows from one sheet based off IDs from another

    Sorry for the slow response.. very busy at work today and didn't have a chance to make a sample page

    Okay so I set up the workbook like this Sheet 1 is the page with the data I want. Sheet 2 is the page that has all the IDs that I want from sheet 1 (listed in column A as the probe set IDs). And finally Sheet 3 is the page I made as a sample with the results I would like after running the script. I added in an additional function that I didn't think of before that would still list IDs that weren't found and just tell me they weren't found in column B if that's not too difficult.

    Thanks so much for any help or advice you can give!! I've only worked with C++ and that was 4 years ago so pretty rusty on coding and learning a new language.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy rows from one sheet based off IDs from another

    Try this code. It works well with small data, but as the data gets bigger the code also gets slow as it has to go through each cell.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Copy rows from one sheet based off IDs from another

    Awesome, yeah my list has about 18,000 items but I only need to do this a couple times so being slow shouldn't be a big deal. I guess the faster way would be to sort it and cut the list in half each time the loop goes through?

    I'll check out this code tonight and let you know how it went. Thanks again!

  6. #6
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Copy rows from one sheet based off IDs from another

    Looks like it worked! Cool

    Am I supposed to mark this thread as solved? How do I do that

  7. #7
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Copy rows from one sheet based off IDs from another

    Looks like it worked! Cool

    Am I supposed to mark this thread as solved? How do I do that
    Last edited by excelforum123; 03-09-2013 at 09:34 PM.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy rows from one sheet based off IDs from another

    Glad to know the code has worked for you!
    Go in to the top right-hand side of this page, choose "Thread Tools" and select solved from the drop-down menu

+ 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