+ Reply to Thread
Results 1 to 5 of 5

Workbook using For loops to compare 2 lists is slow

  1. #1
    Registered User
    Join Date
    12-09-2013
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Workbook using For loops to compare 2 lists is slow

    Hi, this is my first post on the forum, so I'll give a quick bit of background about my Excel/VBA knowledge. I have a basic grasp of the syntax of programming languages (i have some experience with visual basic, html and action script, but I wouldn't say I'm proficient) and I'm aware of quite a few of Excel/VBA's functions.

    I work in a communications team for a large retailer, and we're going through a system changeover in our stores in a couple of months. The system being changed is one which enables us to message stores with important information. While the new system rolls out to stores we will need to send communications to stores using both the old and new systems. If there are any legal issues we need to communicate, we need to ensure that we send the message to the right stores i.e. only send it on the old system to stores still using the old system, only send it on the new system to stores using the new system. These messages may be targeted to certain stores, which poses a problem of sifting through a list of up to 2500 stores and finding which ones are using which system.

    To solve this problem I am developing a workbook where on Sheet 1 the user can input a store list (a simple list of numbers, 1 number per cell), on Sheet 2 there will be a regularly updated list of stores using the new system (again, a simple list of numbers, 1 number per cell). On Sheet 1 is a process button, which when clicked launches a function that finds the stores on Sheet 1 that are also on Sheet 2 and copies them on to Sheet 3, and copies the stores from Sheet 1 that aren't on Sheet 2 on to Sheet 4, creating 2 store lists to be used on the 2 systems.

    I have attached a workbook that contains a working version of this, but it is hideously slow (nested for loops) when I start to ramp up the lists to over 1000 entries.

    I have read in a couple of forums that VLOOKUP can be used to do this sort of thing much faster than using For loops, but I can't seem to get the right result using VLOOKUP. If anyone can provide a bit of help and point me in the right direction to speed this workbook up at all i'd be very appreciative!

    StoreListGeneratorTest.xlsm

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

    Re: Workbook using For loops to compare 2 lists is slow

    Hi Adam,
    It appears you want to compare both sheets. if columns A of both sheet match, you want to copy the matched row in sheet3.Is this right?

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Workbook using For loops to compare 2 lists is slow

    Would it not be easier to maintain ONE table of store code and system in use - then you could easily filter this to show either Old system or New system stores?

    A
    B
    1
    StoreCode
    System
    2
    1
    New
    3
    2
    Old
    4
    3
    New
    5
    4
    Old
    6
    5
    etc
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Workbook using For loops to compare 2 lists is slow

    Here's some code to do exactly what you want, based on your attached workbook:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-09-2013
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Workbook using For loops to compare 2 lists is slow

    Amazing, thanks Olly! That's exactly what I need it to do!

    Just to quickly answer your first question: the store lists I'll need to input onto Sheet1 come from other areas of the business that won't have access to which stores have switched over to our new system, and the list of stores on Sheet2 will be growing day by day as we roll out the system - so I think this is the best solution.

    And now it takes a second rather than five minutes! Thanks again for your help!

+ 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] Slow "for ...Next" Loops
    By francescowimdu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2012, 10:49 AM
  2. [SOLVED] Loops are too Slow.
    By AltNrg4U in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-18-2012, 03:12 PM
  3. Loops using lists
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-29-2011, 03:29 AM
  4. My loops are too slow
    By cheeseboy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2008, 09:40 PM
  5. slow for loops ... better way using arrays or something?
    By wdeleo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 10:35 AM

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