+ Reply to Thread
Results 1 to 3 of 3

Alternative to Xlookup loops for large dataset in a macro?

  1. #1
    Registered User
    Join Date
    01-10-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    2

    Alternative to Xlookup loops for large dataset in a macro?

    Hi all. I'm pretty new to VBA and macros and have been muddling through, but have arrived at a problem I can't solve and I'd really appreciate any advice or help that can be given :-)

    I've got a Sheet with 70,000 customer transactions, and another Sheet in the same Workbook with details about 20,000 customers. I'm trying to add so code to a macro that will go through each of the 70,000 transactions and pull in some info from the relevant line out of the 20,000 customers. I managed to do this with some loops when the data set was MUCH smaller, but using the same process now seems to be making Excel crash - either that or I've not been patient enough to leave it running long enough. Either way, it needs some improvement!!

    A much smaller version of the file is attached to this post, confidential data removed.

    The way my loop was working was to compare the "Customer Number" in the "Distributor Sales" sheet with the "Customer Number" in the "Customer Countries" sheet, and pull out the "Country", "Customer Name" and "Type" back into the "Distributor Sales" sheet. I'd been using these loops:

    Please Login or Register  to view this content.

    Is there a better way to do this without the repeating loops? Perhaps by making the reference data in the "Customer Countries" into an array, or a scripting dictionary? Thanks in advance!!
    Attached Files Attached Files

  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: Alternative to Xlookup loops for large dataset in a macro?

    Hi, and welcome to the forum

    Never use VBA if there is standard excel functionality that can achieve what you want.
    VBA is much slower than standard Excel and particularly where loops that refer back to Excel at each pass through the loop are used since there's a time overhead for VBA to jump to Excel and back to VBA.

    In your case in T2 on the Distributor Sales sheet enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and copy it down. The '4' means the 4th column so for other stuff like Country and Name change to 2 & 3

    If this is something you do regularly then write a macro which will add the formulae for you.
    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-10-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Alternative to Xlookup loops for large dataset in a macro?

    Richard - that's amazing, thank you SO MUCH! Sorted everything :-D

+ 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. Find and replace large number of values in large dataset.
    By Brutu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2021, 10:54 AM
  2. Xlookup alternative
    By showboat in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 12-07-2020, 09:19 PM
  3. [SOLVED] macro that colours each cell that contains a unique value in the column in a large dataset
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-03-2020, 01:39 AM
  4. Macro for Detailed Percentage? Large dataset
    By 1MooreMike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2019, 11:53 AM
  5. Replies: 3
    Last Post: 10-20-2017, 12:40 AM
  6. Replies: 3
    Last Post: 01-23-2014, 10:13 AM
  7. Small macro for XY plot for large dataset
    By Celsiane in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-26-2013, 12:36 PM

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