+ Reply to Thread
Results 1 to 8 of 8

Excel Macro searching value in an array taking really long

  1. #1
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Excel Macro searching value in an array taking really long

    Hello everyone,
    I wrote the following code seeking help from here and there. The code looks for a value starting from B2 on the worksheet 'ReferenceSheet_CustomerNo' and compares it against the values in column G across each and every spreadsheet (another macro called 'SelectFilesforCopy' helps in choosing the files) and extracts the rows and paste in the worksheet 'Combined'. The problem is the code is working fine when I work with few sheets but when the number increases the macro takes really long. I was wondering if any of you can help me in improving the code or making it faster.
    Please Login or Register  to view this content.
    I have to use this macro to check values from a column with 100s of customer numbers against the ones with 10s of thousands of numbers. I have wasted many hours trying different things but nothing is working. I really appreciate if any one would help me in improving this code.

    thanks!
    Last edited by realdemigod; 09-17-2014 at 06:22 AM.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Excel Macro searching value in an array taking really long

    See if this helps

    Please Login or Register  to view this content.
    Thanks

  3. #3
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Excel Macro searching value in an array taking really long

    Hi fredlo2010,
    A Big Thanks! Your code works like magic, super fast. It takes less than 2 seconds to populate the data while my code took at least 8mins to do the same. Could you please tell me why my code took such long time compared to yours?

    I made a minor modification as the data selected is short of one value.

    Appreciate your great help!

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Excel Macro searching value in an array taking really long

    These were the issues I saw
    1. Loop inside a loop inside a loop
      This is very bad and it takes a long time to process because the amount of times the code has to loop grows exponentially.
      Fix:
      Use a faster way to match data; Match, Find, VLookUp...
      Also Fix one side of the data and make the rest pivot. For ex: Get one of the records and look for it in each sheet. Rather than get a each record and look for it in a sheet and then repeat the process for each sheet.
    2. Copying full row
      If you dont need the full row only copy the data you need. And use the Copy Destination.
    3. Calculations automatic
      Turn this off so the sheet does not have to be calculated every time there is a change.
    4. Select
      Select or activate slows down the code. Refer to objects all the time so you dont have to select.

    I am glad I was able to help.

  5. #5
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Excel Macro searching value in an array taking really long

    Thanks for your tricks . I knew those nested loops were slowing down the code but I didn't know any better. Glad to have people like you around

  6. #6
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Excel Macro searching value in an array taking really long

    Hello fredlo2010,
    In the code you provided I made small change for getting the matched record against two columns of reference data. I have attached the sample data file here. I'm hoping the line below gives the record only when GeoarrData = column K and arrData = column S (checking individual cells). But when I run the code it takes sometime and shows no rows in the output sheet ("Combined").

    Please Login or Register  to view this content.
    I must be doing something blatantly wrong. Could you or any expert here please help.

    Thanks!
    Attached Files Attached Files
    Last edited by realdemigod; 09-17-2014 at 01:28 PM.

  7. #7
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Excel Macro searching value in an array taking really long

    Post Edit: Removing content to avoid confusion

    Mods, please delete this post, thanks.
    Last edited by realdemigod; 09-17-2014 at 01:13 PM.

  8. #8
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Excel Macro searching value in an array taking really long

    Post Edit: Removing content to avoid confusion

    Mods, please delete this post, thanks.
    Last edited by realdemigod; 09-17-2014 at 01:13 PM.

+ 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. Array Formulas taking too long to calculate
    By CheeksExcelForum in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-17-2013, 06:56 PM
  2. Macro taking too long to finish
    By DKAbi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2013, 06:23 PM
  3. Macro taking too long to execute
    By jacob@thepenpoint in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2012, 05:13 PM
  4. [SOLVED] Array Formula taking too Long
    By gborja888 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2012, 03:41 AM
  5. Excel (2003) array formula taking too long
    By Krazy Kasper in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-11-2008, 11:26 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