+ Reply to Thread
Results 1 to 7 of 7

Macro keeps causing excel to freeze

  1. #1
    Forum Contributor
    Join Date
    08-02-2005
    Location
    LONDON
    MS-Off Ver
    OFFICE365
    Posts
    167

    Macro keeps causing excel to freeze

    Hi

    I have the following macro and when I run it keeps causing excel to freeze up saying not enough memory. I closed all other excel sheets to reduce but still freezes up.

    There are over 40,000 entries it trying to compare. Is there anyway I can change it so it dont keep freezing up.

    Thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    Maybe Excel is not frozen but just working as a VBA loop is slow …
    Adding a DoEvents codeline before Next may cause Excel to not freeze but could run a bit slower.

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Macro keeps causing excel to freeze

    Rather than loop and put the formula in each time I'd put the formula in all cells at once then loop through the results.

    Without a sample workbook this is not tested but try this:
    Please Login or Register  to view this content.
    No idea if it will help but worth a try.

    BSB

  4. #4
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Macro keeps causing excel to freeze

    The less interaction with the worksheet, the faster the code. Without an example file probably
    Please Login or Register  to view this content.
    Last edited by Vraag en antwoord; 07-06-2019 at 08:39 AM.

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Macro keeps causing excel to freeze

    Quote Originally Posted by Marc L View Post
    Maybe Excel is not frozen but just working as a VBA loop is slow
    That wouldn't return the 'not enough memory' message that the OP encountered.
    A variation of BSB's code revision that eliminates the loop entirely.
    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Macro keeps causing excel to freeze

    @jason.b75, Have you tested your brilliant idea on 40k rows? Countifs is very slow. respond to respond?

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Macro keeps causing excel to freeze

    I made no claim of how good it would be, just offered it as an alternative. Given that we don't have the distribution ratio of those 40k rows it is impossible to judge accurately how well any suggestion will perform. 40k rows in each sheet will be slow with countifs, 40k rows total over both sheets will vary depending on the split, a 50/50 ratio will be slower than a 60/40 or 40/60, which will be slower than 70/30 or 30/70, etc.

    Whilst I doubt that it will be the case with this thread, it is theoretically possible that countifs might be faster than your method with the ratio highly biased toward either of the two sheets.

    I have noted an error in my suggestion, which is corrected below.
    Please Login or Register  to view this content.

+ 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. Undo causing page to freeze
    By DukeRollo in forum Excel General
    Replies: 11
    Last Post: 04-29-2019, 04:03 AM
  2. Macro causing excel to crash
    By bradleyandrewdavis in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-16-2015, 04:29 AM
  3. ClearContent Macro causing Excel crash.
    By Phily915 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2014, 12:54 PM
  4. [SOLVED] Macro causing Excel to freeze
    By Sassyponypants in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2013, 06:10 AM
  5. Macro causing Excel to freeze - intended to hide cells with zero value
    By ParkingExcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2012, 02:11 AM
  6. macro adjustment needed causing freeze
    By ryanb4614 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2010, 09:46 PM
  7. .Find Loop causing Excel to freeze
    By trippin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-21-2010, 09:52 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