+ Reply to Thread
Results 1 to 6 of 6

Slow Macro Execution

  1. #1
    Registered User
    Join Date
    09-04-2013
    Location
    richardson, tx
    MS-Off Ver
    Excel 20037
    Posts
    28

    Slow Macro Execution

    I created a macro to retrieve data from a worksheet based on the contents of a cell within the same workbook. However, the macro runs slowly at first then gets slower. The workbook has several worksheets but I am only using 2. I import customer data into Sheets(1) and have my search data formatted as text - this is a column of numbers which I do not want to treat as numbers. The search numbers in Sheets(1) are a subset of the complete number in Sheets(2). For example, in Sheets(1), I use 062825 to search Sheets(2) to find 011874000061825. Numbers in both sheets are formatted as text.

    I sort both sheets on the data value I am interested in then use a For..Next loop to grab each input value and search Sheets(2). I included a code fragment below for evaluation. All variables are initialized prior to For loop. At this time, Sheets(1) has 250 lines while Sheets(2) has approx 1357 lines.

    Any comments will be appreciated.

    Please Login or Register  to view this content.
    Thank you
    Gandalf2524
    Last edited by Gandalf2524; 09-04-2013 at 04:15 PM. Reason: add code tags

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Slow Macro Execution

    Hi

    You should avoid for next loops like the plague.

    They are excellent for small loops but will really slowdown macro operation as they get bigger.

    Instead use the find function to find your data. Something like the code below


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-04-2013
    Location
    richardson, tx
    MS-Off Ver
    Excel 20037
    Posts
    28

    Re: Slow Macro Execution

    Thank you for your quick response. The code works much better. However, I need to cycle through a list of values on Sheets(1) and find corresponding serial numbers on Sheets(2). How do I advance to the 2nd value on Sheets(1) after finding the 1st result?

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Slow Macro Execution

    just change the search string,

  5. #5
    Registered User
    Join Date
    09-04-2013
    Location
    richardson, tx
    MS-Off Ver
    Excel 20037
    Posts
    28

    Re: Slow Macro Execution

    suggestions worked great, thanks mehmetcik

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Slow Macro Execution

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED",as per our Forum Rule #9. I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --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.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ 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. Slow VBA execution
    By GustavBA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 06:40 AM
  2. Slow Macro execution
    By rickparker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2012, 11:16 AM
  3. [SOLVED] Help - Excel 2003 Macro execution SLOW!
    By C C in forum Excel General
    Replies: 5
    Last Post: 12-02-2005, 12:35 PM
  4. Slow code execution
    By side_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2005, 01:44 PM
  5. [SOLVED] Macro Slow In Execution Under Excel 2002
    By samson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2005, 04: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