+ Reply to Thread
Results 1 to 6 of 6

Find and copy

  1. #1
    Registered User
    Join Date
    01-23-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2007
    Posts
    4

    Find and copy

    I have a list of ID numbers listed in a column on one worksheet. I want to find a subset of these ID numbers in another worksheet, copy the entire row associated with the ID number and paste the row it into yet another worksheet.

    This is my first attempt at writing some vba code and any help would be greatly appreciated as I really don't want to do all this by hand.

    Here is what I have have tried so far:
    Please Login or Register  to view this content.

  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: Find and copy

    Hi,

    Try something like the following. Adjust the sheet references as necessary. It assumes you start on Sheet1 with a value in the Active Cell. It looks to sheet2 for that value in col C and pastes the whole row back in sheet1. Note that .Select and .Activate are rarely ever needed in code. they only slow down the execution and get in the way. After you've used the macro recorder which always captures these instructions just edit and remove them. You can always address object directly without needing to activate them.

    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 01-23-2010 at 05:33 PM.
    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
    Registered User
    Join Date
    01-23-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and copy

    Thanks for the help.

    I have one problem however. I used your code and put in the correct sheet names and I get run-time error 1004, application-defined or object-defined error.

    When I try to debug this, it says it has a problem in the last line of code (the one starting with Sheets...).

    Any ideas? Also, is everything case sensitive? It won't let me capitalize one word (constantly changes my Copy to copy) and I know other programs I am familiar with are very case sensitive.

    Thanks again.

  4. #4
    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: Find and copy

    Hi,

    Can you upload the workbook so I can take a look. Anonymise the data if it's sensitive.

    Rgds

  5. #5
    Registered User
    Join Date
    01-23-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and copy

    Here is a smaller version of made up numbers.

    The first sheet has the ID numbers, the second sheet has the data. Ideally I'd like to paste the matching data to the third sheet.

    Thanks again for taking the time to help.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-23-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and copy

    For anyone who is interested, I was able to get it to work. Here is the not so elegant code I am using to get the job done.

    Thanks for all the help, wouldn't have figured it out otherwise.

    Please Login or Register  to view this content.

+ 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