+ Reply to Thread
Results 1 to 8 of 8

Not enough memory to run

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Question Not enough memory to run

    Hi, everyone

    I have this code to copy from one workbook to another:

    Please Login or Register  to view this content.
    But a message will pop out, saying that I don't have enough memory. Anyone knows any other way to alter this?

    Thanks in advance.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Not enough memory to run

    Give this a try.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,494

    Re: Not enough memory to run

    To give some explanation to your code used.. and the cause of the problem.

    on line
    Please Login or Register  to view this content.
    you are telling excel to copy 108 columns from workbook to workbook y but those 108 columns each have 1,048,576 cells, so you are copying 113+ MILJON cells..
    that will take a good while
    even if your workbook has 5000 lines you would still only have just over a 0,5 miljon cells in the usedrange.. so 113 miljon is a bit of overkill to copy

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,338

    Re: Not enough memory to run

    Or something like this. (because UsedRange sometimes gives unexpected results)
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Not enough memory to run

    Quote Originally Posted by bakerman2 View Post
    Or something like this. (because UsedRange sometimes gives unexpected results)
    Usedrange is very predictable in a newly opened workbook.

  6. #6
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Not enough memory to run

    Hi, all

    Thank you so much for your attention and time in this post. Really appreciate it. But I was wondering:

    Quote Originally Posted by bakerman2 View Post
    Or something like this. (because UsedRange sometimes gives unexpected results)
    What does Bakerman means in this? Because I previously used UsedRange in my other code.

    FYI, I can't seem to work with Bakerman's code as it shows an error in this line:

    Please Login or Register  to view this content.
    It says that the subscript is out of range. Not sure why

    But thanks to AlphaFrog, your code works! And to Roel for your explanation.
    Last edited by ell_; 04-20-2018 at 11:57 PM.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Not enough memory to run

    The UsedRange is recalculated when the workbook is opened or saved. So if you were to delete or clear some rows of data and visually the used range looks smaller, the actual UsedRange doesn't change until you save the workbook.

    In this instance, the macro only opens the workbook and copies the data. But if you want to be extra careful, bakerman2 is correct.

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

    Lightbulb Hi ! A Master tip !


    Quote Originally Posted by AlphaFrog View Post
    the actual UsedRange doesn't change until you save the workbook.
    No need to save, just insert before this single codeline in the procedure : ActiveSheet.UsedRange

    Or any valid worksheet reference instead of Activesheet.

+ 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. Out if Memory - what to do?
    By Deschutes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2012, 03:34 PM
  3. Replies: 1
    Last Post: 12-08-2011, 08:52 AM
  4. Need VBA to find out memory and virtual memory used by thread
    By Yozhik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2011, 08:31 AM
  5. Out of Memory:Is there any way in which I can restore the memory that got used up dur
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2009, 07:15 AM
  6. Out of memory
    By Harrymo in forum Excel General
    Replies: 1
    Last Post: 01-25-2006, 10:45 AM
  7. Vba Memory
    By billy2willy in forum Excel General
    Replies: 2
    Last Post: 08-16-2005, 08:05 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