+ Reply to Thread
Results 1 to 5 of 5

stack memory error

  1. #1
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    stack memory error

    I am trying to figure out why this code is causing a stack memory error. The machine I am using has 4GB of memory.
    Here is the code:
    Please Login or Register  to view this content.
    I have attached the sheet as well. I need suggestions for how to either rewrite the code so as to not cause the error or new code that works. It is to total column E3 to the last row entered and display the total in cell F2.
    Any help is greatly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: stack memory error

    Does the code fail on a specific line?

    Just an FYI, the amount of RAM your computer has isnt as crucial as you might think at least for 32bit Excel. Excel x32 can only use 2GB of RAM per instance (not to be confused with per window or per workbook). Excel x64 can essentially utilize however much RAM the system has (there may be some upper limit but I am sure its absurdly high).

    I dont see anything at a glance that would cause the issue. Typically I see that error when people try and store stuff in odd ways.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,837

    Re: stack memory error

    I would guess that the stack overflow error is because each time the change event is called, it makes a change to the spreadsheet, which calls the change event, which makes a change in the spreadsheet, which calls the change event, which...(I hope you get the idea). You essentially have an infinite loop/recursion that eventually will overflow the call stack.

    I think this is the kind of scenario where you need to use the application.enableevents property to turn off events before the procedure makes changes, then re-enable events when the code is done: https://msdn.microsoft.com/en-us/VBA...property-excel

    On edit: If I understand what the code is doing, it looks like it is basically conditional formatting/color of cells, and a SUM() function. I would not be surprised if this change event could be eliminated by using built in conditional formatting and a SUM(E:E) function in the appropriate cell.
    Last edited by MrShorty; 01-26-2018 at 01:57 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: stack memory error

    It errors at:
    Please Login or Register  to view this content.
    Computer is running Windows 7, 64 bit with 4 GB memory excel 2016 32bit. And I think I just figured out the problem. My laptop, which I use to program is running Excel 365 64 bit, and the company computers are running the Excel 2016 32 bit. I am going to contact our IT department to see if they can upgrade the software to 64 bit since we are running the Windows 64 bit.
    Thanks for your help.

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: stack memory error

    Quote Originally Posted by COURTTROOPER View Post
    I am going to contact our IT department to see if they can upgrade the software to 64 bit since we are running the Windows 64 bit.
    I should clarify that switching to x64 is unlikely to be the right solution. You will be correcting the symptom, not the cause of the issue. 99% of people using Excel do NOT need x64, Microsoft still recommends x32 for most people. The reason being that many addins are still not compatible with x64 Excel (its getting better tho) and some VBA code (mostly those calling API's) would need to be updated to account for a 64bit version of Excel.

    Could a 64bit version prevent memory related errors from coming up...sure. Does it actually correct the issue that caused those errors...no.

    As mentioned by MrShorty (and I am embarrassed I overlooked it) you are running that code in an event, which also triggers itself. This likely causes issues. Its typical in an event like this to have the event code disable events, make the changes required, then re-enable events.

    Going to 64bit to fix this would be like buying a new car because you dont know were the turn signal is on your old car. Another analogy; its like eating fried food and having high cholesterol so the dr puts you on medication. Does your cholesterol go down, sure...but if your still eating fried food you havent addressed the problem, only the symptoms.

    EDIT: Another warning against x64 in this situation. You are raising the ceiling for which an issue can get to before causing an error. In the 32bit version you get an error and everything is "ok" (in that you can still use your file and try and correct the problem). In a 64bit version it may work for now, but without correcting the cause of the issue it may grow and grow until you get to the point that not only does it stop working but you also are unable to use the file or correct the issue.
    Last edited by Zer0Cool; 01-26-2018 at 03:31 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. [SOLVED] Thrashing VBA Memory Leaks. Memory Loop Problems. Uncleared Memory in .Match Range Object
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2017, 05:17 PM
  2. [SOLVED] Out of stack error
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-13-2016, 04:09 PM
  3. [SOLVED] Error 28 Stack Space
    By scrabtree23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2015, 09:58 AM
  4. Out of stack space error
    By lazyengineer in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-10-2015, 02:24 PM
  5. Replies: 1
    Last Post: 12-08-2011, 08:52 AM
  6. Having stack/heap memory in Excel VBA
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2005, 03:51 PM
  7. [SOLVED] Application Run Time Error 1004 and Stack Error
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-11-2005, 01:06 PM

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