+ Reply to Thread
Results 1 to 19 of 19

How to macro multiple lookups on over 500,000 rows of data efficiently?

  1. #1
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    How to macro multiple lookups on over 500,000 rows of data efficiently?

    Hi Excel Forums.

    I am posting again as my previous post did not provide enough information for people to be able to help. I have now made a dummy spreadsheet with some data added in to explain my problem a bit better.


    In the first sheet, the data that is filled out is received from a report that is auto generated. I want to fill out the remaining 3 cells using a Macro and information on the other sheets. The self-approval column should say yes if the employee's band allows them to approve the invoice amount (found in sheet 2). It should say no if they are not allowed to approve themselves, in which case the next cell should populate with the details of their manager (found in sheet 3). If that manager cannot approve due to their band being lower, then it follows onto their manager and so on until the correct approval party is there. This file has 350,000 rows of data.


    Sheet 2 shows the proposed amounts each band can approve. These limits will be changed and altered to see which method provides the best coverage.


    Sheet 3 shows employee details extracted from a database. Has over 25 fields of information but cut down to show the ones I will be using. This file has 402,000 rows of data.


    I have currently toyed with a Macro, where the self-approval populates based on variables stored from Sheet 2 into the Macro and then inputs yes/no into the self-approval cell. That works fine. The only roadblock I am facing is when I use too many if's to check for a managers band code, which results in the macro looping again and again for all the rows of data. What is the most efficient way to do this, please?
    Attached Files Attached Files

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

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Use PQ(Power Query). Easy and could handle massive data.

  3. #3
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Thank you so much for your response. I've just had a go at trying it, but I'm unsure about how to use it to get my solution. So far I've loaded the different sheets into a query.

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

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?


  5. #5
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    I've just been searching around and the only issue with a power query would be that it does not allow me to loop through the signing authority hierarchy; that is to say, if the managers band does not authorise a sign-off, then my sheet needs to look for THEIR manager and confirm if they can signoff.

  6. #6
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    a first attempt
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  7. #7
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Thank you so much for your response, I've manually typed out the code on my other laptop and it is so much more efficient than my current code. It is still running on that machine as the data is very, very large so it might take a very long time for it to compute.

    But I hit the same roadblock as I have done on my previous code, too: when the manager sign-off fails, it should loop until it goes up the hierarchy and list the next manager that can approve. I have attached the updated employee details sheet which has a new manager that should be able to approve invoice number 1.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    see attachment

    the first 2 buttoms are for adding and deleting 400.000 records (otherwise it doesn't fit on this site)
    the 3rd one is to approve.
    20 seconds for 400.000 records.
    Quick enough ?
    the table of the employees, you only have to add the id of the manager, the rest are formulas (or do you prefer his name ?)
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Try this code
    Pl note the change in Sheet "Proposed Limits". Column D is added.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 12-15-2021 at 01:31 PM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  10. #10
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Hi, thank you so much for the solution. My final spreadsheet looks a bit like this; is it possible to alter the formula to work on this please? The columns are different.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Hi, I really want to try this on my spreadsheet but the final spreadsheet looks a bit different to this. Can I please get the code that is relevant to the one I have pasted in please? The highlighted columns are the relevant ones.
    Attached Files Attached Files

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Why waste so much of members' precious time by uploading a sample file that does not represent your actual file...I see this happen so often where users supply sample files...get solutions and then have no clue how to amend the code to use in their real files...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  13. #13
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Hi, you're right. I should've been more careful of that. I apologise for this instance and it won't happen again. It was an attempt from my side to make the task easier to explain, but it ended up not working out for me.

  14. #14
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    There is no data in "Employees Details" sheet. Put some required data. Also Write the expected result in the Invoice Details sheet.

  15. #15
    Registered User
    Join Date
    12-14-2021
    Location
    London, England
    MS-Off Ver
    Windows Office 2016
    Posts
    10

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Hello, sorry about that. I have attached it now.
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    Here is the revised code. Code also changed assuming that the manager name comes after the Employee name in Employee details sheet in D column, to make code faster.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 12-16-2021 at 12:49 PM.

  17. #17
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    with 6 reads, 2 writes and all the rest in memory, my code is rather quick, i assume.
    Attached Files Attached Files

  18. #18
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    If you are having problems in my previous code use this code .
    Please Login or Register  to view this content.

  19. #19
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How to macro multiple lookups on over 500,000 rows of data efficiently?

    when the manager sign-off fails, it should loop until it goes up the hierarchy and list the next manager that can approve.
    I did something evil.
    I added several employees and gave them a manager just 1 band lower.
    Then i created 100 invoices with a random amount and a random employee.
    If an approval isn't ok then column P is conditional coloured orange.

    Both macros are now in place and can be activated by their commandbutton.
    I think only my macro goes up in the hierarchy to find a fitting manager.
    apologise if i'm wrong.

    EDIT : it has something to do with the "band_" in column N.
    It's perhaps better to omit that part in the limits-tab, because that causes problems for both of us.
    Attached Files Attached Files
    Last edited by bsalv; 12-17-2021 at 07:52 AM.

+ 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. Replies: 13
    Last Post: 06-09-2017, 12:57 AM
  2. Replies: 1
    Last Post: 05-28-2017, 09:41 PM
  3. [SOLVED] Multiple combined lookups across sheets and rows
    By bgcm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-15-2015, 02:21 PM
  4. [SOLVED] Macro to more efficiently copy/paste every 21 rows
    By Phil_Packer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-23-2013, 03:08 AM
  5. Reconciling Multiple Tables of Data Efficiently
    By EK923 in forum Excel General
    Replies: 10
    Last Post: 08-15-2012, 06:21 PM
  6. Stuck with VBA and data import/lookups on different rows
    By mradam87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2010, 03:59 PM
  7. how to efficiently send many rows of data on a worksheet to the database using vba?
    By gozitash in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2005, 11:06 AM

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