+ Reply to Thread
Results 1 to 7 of 7

Find and copy between sheets (workbooks)

  1. #1
    Registered User
    Join Date
    11-07-2019
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    8

    Wink Find and copy between sheets (workbooks)

    Hi, Im pretty new into programming with VBA in excel I got my code working but its just too slow.

    Could you guys help me speeding up my task.

    Sheet2 (database) has around 42.000 items and sheet1 (part of database) varies from 100 to 1000

    Basicly I look for a value in 2 sheets when there is a match I copy the info into sheet1 from sheet2.

    See my code below.

    Would be nice to improve the code to replace sheet2 with an workbook.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Find and copy between sheets (workbooks)

    The looping approach you used with 42.000 items can take some time to run. Try this macro. If I understood correctly what you want to do, it should be quite fast.
    Please Login or Register  to view this content.
    This assumes both sheets are in the same workbook. If you want to use Sheet2 from a different workbook, what is the full name of that workbook including extension (xlsx, xlsm)? Are your actual sheet names "Sheet1" and "Sheet2"? If not, what are the actual names?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Find and copy between sheets (workbooks)

    Hi there,

    See if the following code does what you need - when I used it with a "Sheet 2" containing 42,000 items and a "Sheet 1" containing 1,000, it executed in approximately one second:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M


    P. S. When this routine was executed using random numbers with a greater range of values, the execution time increased significantly - in the earlier executions, duplicate random numbers were probably found more quickly if they were located closer to the top of the column being searched.
    Last edited by Greg M; 11-07-2019 at 11:02 AM. Reason: P. S. added

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Find and copy between sheets (workbooks)

    Hi Mumps,

    Thanks for introducing me to a whole new approach!

    I normally don't use Scripting Dictionaries, so I hadn't realised that the Exists property seems to be a lot faster than the Find method of a range.

    Regards,

    Greg M

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Find and copy between sheets (workbooks)

    @Greg M
    Glad it was of some help.

  6. #6
    Registered User
    Join Date
    11-07-2019
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    8

    Re: Find and copy between sheets (workbooks)

    Thanks alot code works like a charm!!!! sheets are called "AML" (sheet1) and "DATA"(sheet2) if I would take sheet2 seperate I would call it "DATA.xlsx" also.

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Find and copy between sheets (workbooks)

    Place this macro in the workbook that contains the "AML" sheet. Make sure that both workbooks are open and run the macro.
    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)

Similar Threads

  1. [SOLVED] Copy sheets from two workbooks to another workbook
    By sreeks in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-28-2014, 01:44 PM
  2. [SOLVED] VBA to copy certain sheets from various workbooks into new workbook
    By Alice21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2013, 11:05 AM
  3. Copy sheets from various workbooks
    By Stu c in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-24-2013, 10:09 AM
  4. Copy sheets from different workbooks to specific sheets in one workbook
    By erikfae in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2011, 08:02 AM
  5. copy sheets from workbooks to one workbook
    By soso123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2011, 05:53 AM
  6. Copy\Find\Copy\Paste Multiple Workbooks
    By JMcClane in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2010, 10:23 AM
  7. How Do I Copy Several Sheets into New Workbooks
    By tannerL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2008, 10:59 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