Consulting

Results 1 to 5 of 5

Thread: Sleeper: Memory or Cache Problem

  1. #1
    VBAX Newbie
    Joined
    May 2005
    Posts
    1
    Location

    Sleeper: Memory or Cache Problem

    I am working with Excel 2003 on Windsows XP. I am fairly good in coding VBA and Excel in general, but I am stumped on this one. I am having an issue with large spreadsheets (containing multiple spreadsheets each with many VLOOKUP statements).

    Specifically - I have a Workbook with approximately 40 - 50 spreadsheets in it - each conaining 40 - 50 VLOOKUP statements. The Workbook is then in the 8 - 10 MB range before it is converted to a new Workbook.

    Each time I try to convert this Workbook to a new one (a duplicate Workbook with only minor date changes) - I keep getting the following message after about 6 - 8 spreadsheets are created:

    *********************************************************
    Run time error '1004'

    Copy method of Worksheet class failed
    *********************************************************

    If I close the Workbook and shut down Excel and restart Excel, it can sometimes create a few more spreadsheet - but never all of them in one pass.

    In researching the problem, I believe that there is code in VBA that will allow me to clear (e.g. Reset or Clear) the internal memory in Excel, BUT I cannot find any examples of how to enter the code.

    I have tried clearing the Clipboard with each new spreadsheet created, but this has not helped.

    *********************************************************
    Application.CutCopyMode = False
    *********************************************************

    Are there any examples of code that I can use in my VBA module that will allow me to clear the Excel memory while Excel is active?

    Thanks for the help.
    [img]file:///C:/DOCUME%7E1/MARK/LOCALS%7E1/TEMP/moz-screenshot-2.jpg[/img]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi ColH
    Welcome to VBAX.
    This is a bit out of my expertise. I tried the following code to simulate your problem

    Sub DoCopy()
        Application.DisplayAlerts = False
        For i = 1 To 50
            Sheets("Sheet1").Copy Before:=Workbooks("testnew.xls").Sheets(1)
            Debug.Print Application.MemoryFree & " bytes free"
        Next
        Application.DisplayAlerts = True
    End Sub

    The macro is halting during execution after 26 copies. The memory free figure figure remained constant as 1048576 bytes free, and the code will not run again until excel is closed and reopened.
    HTH
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Application.MemoryFree, unfortunately, doesn't work! It always returns 1MB.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Col_H,

    Welcome to VBAX!

    I don't know a huge amount about it, but Excel has its own memory manager and built in limits. Sooner or later, everybody runs into one or other of the limits and there really isn't much you can do about it.

    That said, your error message doesn't actually specify memory problems, and the limits have been vastly increased in 2003 so (assuming your physical memeory and/or swap file are big enough) you may have another problem.

    Can you successfully open two copies of your workbook at the same time in one instance of Excel?

    If you're trying to duplicate the whole workbook, why not just use Windows Copy and Paste?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by TonyJollans
    Hi Col_H,

    ...

    If you're trying to duplicate the whole workbook, why not just use Windows Copy and Paste?
    that was my first thought.

    I have had problems in the past trying to be elegant about copying, i.e., only parts and pieces and ran into problems. I ended up just copying the whole thing and then editing out what I did not want ...
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •