Excel exceeding usable RAM and "crash"

  • Hello all, I have problem with 2 inside cycles. Because Excel increasing amount of used RAM each cycle and when reach max amount of usable RAM (around 1,6GB) then stops, give me a error message that there are not free RAM and I have to force shut down the Excel. All others cycles what I using in other macros working OK, only this part of code:


  • Re: Excel exceeding usable RAM and "crash"


    What's the code for GetInfoFromClosedFile?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Excel exceeding usable RAM and "crash"


    Quote from rory;787385

    What's the code for GetInfoFromClosedFile?


    Code
    Private Function GetInfoFromClosedFile(ByVal wbPath As String, _    wbName As String, wsName As String, cellRef As String) As Variant
    Dim arg As String
        GetInfoFromClosedFile = ""
        arg = "'" & wbPath & "[" & wbName & "]" & _
            wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
        On Error Resume Next
        GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
    End Function


    But I mean it's not a problem, because when I erase all/most content inside cycle then it is the same situation - RAM usage still raising each cycle.

  • Re: Excel exceeding usable RAM and "crash"


    You have given the variable "y" a value of zero

    Code
    y=0


    then in your loop you use

    Code
    For i = 1 to y

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel exceeding usable RAM and "crash"


    I'm not sure if I understand right what you mean, because I need y to have value of number of rows in the sheet all the time. So you mean to set it to zero and in next cycle set it agait to the value I need?

  • Re: Excel exceeding usable RAM and "crash"


    No, I do not mean that.


    Look at your code, you set the value of y to be 0.
    If you need it to be the number of rows then set it to that.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel exceeding usable RAM and "crash"


    Sorry my fault, y have to be set to last empty row of the sheet and it is in my original file (i have edited the example to the right version)

  • Re: Excel exceeding usable RAM and "crash"


    OK that makes more sense now :)


    Very difficult to tell why the crash occurs, could be because of the number of rows of data involved.


    Can you attach your workbook.
    [sw]*[/sw]

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel exceeding usable RAM and "crash"


    You could try adding

    Code
    Application.ScreenUpdating = 1
    Application.ScreenUpdating = 0


    at the end of the first loop, that is above this line

    Code
    Loop


    Updating the screen will release the data from the computer memory and thus restore available RAM. Also, remove the Saving of the workbook in the Do loop, there is no need to save it for every iteration of the Do loop when it gets saved at the end of the code, you probably don't need DoEvents either.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel exceeding usable RAM and "crash"


    It's still the same result. But if I erase all rows inside the i,y cycle, then it works fine, still slow, but memory is still on the same amount.

  • Re: Excel exceeding usable RAM and "crash"


    Now it looks problem is in function below:


    Code
    Private Function GetInfoFromClosedFile(ByVal wbPath As String, _    wbName As String, wsName As String, cellRef As String) As Variant
    Dim arg As String
        GetInfoFromClosedFile = ""
    '    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    '    If Dir(wbPath & "\" & wbName) = "" Then Exit Function
        arg = "'" & wbPath & "[" & wbName & "]" & _
            wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
        On Error Resume Next
        GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
    End Function
  • Re: Excel exceeding usable RAM and &quot;crash&quot;


    You really need to attach your workbook.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel exceeding usable RAM and &quot;crash&quot;


    It is difficult, because it contains sensitive data and links to files stored in company network...I will try prepare something with the same problem.

  • Re: Excel exceeding usable RAM and &quot;crash&quot;


    Hello,


    Just tested the following with is working fine ...

    Code
    Private Function GetInfoFromClosedFile(ByVal wbPath As String, wbName As String, wsName As String, cellRef As String)
        Dim arg As String
        arg = "'" & wbPath & "[" & wbName & "]" & _
            wsName & "'!" & Range(cellRef).Address(True, True, -4150)
        GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
    End Function


    HTH

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Excel exceeding usable RAM and &quot;crash&quot;


    Hello,


    Sorry ... I am unable to replicate your problem ... and private function does operate smoothly ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Excel exceeding usable RAM and &quot;crash&quot;


    Maybe because it is just a sample of original file, where I have more than 9000 records? The test file works smoothly for me too.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!