+ Reply to Thread
Results 1 to 9 of 9

Memory Error - Need help to optimize VBA code

  1. #1
    Registered User
    Join Date
    05-18-2013
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Memory Error - Need help to optimize VBA code

    I am using VBA to find and replace currency formats across all worksheets based on currency selection in a particular cell. The code works just fine functionally, but I often run into an error - "There is not enough memory to complete this operation. Try using less data or closing other applications."

    I am new to VBA and I believe this is because my code isn't optimal in its usage of memory. Below is the code for the whole function. The yellow highlighted area is where the VBA stops executing and throws the memory error. I will be very thankful for a solution!


    Update - I have attached a sample workbook with the current code and the objective explained within.

    Please note that while this sample workbook only handles 2 currencies in 2 worksheets, I need this code to optimally work over 5 data-intensive tabs with 10+ currencies

    Problem - In the actual workbook, I often run into a memory error as described previously.

    Request Assistance in - Please help me optimize the code in this attached example workbook to utilize less memory so that the memory error does not show up in my actual workbook.




    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by pgk_05; 07-27-2020 at 09:45 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Memory Error - Need help to optimize VBA code

    Hi

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.

    It's not clear why you're using a UDF rather than a standard Procedure, and cycling through every cell in a loop is almost certainly not the most optimum way.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,467

    Re: Memory Error - Need help to optimize VBA code

    Just running a simple test, these lines error:

    Please Login or Register  to view this content.
    That might just be because I don't have appropriate date and/or formatting.

    There are other, simpler ways of referencing the Named Ranges. Some comparisons:

    Please Login or Register  to view this content.

    If you upload a sample file, we can test your code in its own environment.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    05-18-2013
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Memory Error - Need help to optimize VBA code

    Thanks a lot for your responses.


    I have attached a sample workbook with the current code and the objective explained within.

    Please note that while this sample workbook only handles 2 currencies in 2 worksheets, I need this code to optimally work over 5 data-intensive tabs with 10+ currencies

    Problem - In the actual workbook, I often run into a memory error as described previously.

    Request Assistance in - Please help me optimize the code in this attached example workbook to utilize less memory so that the memory error does not show up in my actual workbook.


    Thanks a lot again!
    Attached Files Attached Files
    Last edited by pgk_05; 07-20-2020 at 11:30 AM.

  5. #5
    Registered User
    Join Date
    05-18-2013
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Memory Error - Need help to optimize VBA code

    Bumping this up. I'll be thankful for any help on this. Thanks!

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Memory Error - Need help to optimize VBA code

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    As you are new I will add it for you this time
    https://www.excelguru.ca/forums/show...imize-VBA-code

  7. #7
    Registered User
    Join Date
    05-18-2013
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Memory Error - Need help to optimize VBA code

    My apologies. I wasn't aware of the cross-posting rule. The link you shared in your reply is the ONLY other forum where this query is posted.

    I am unable to embed the same link in this response.

    PS - I am still looking for assistance on this and I will be grateful for any help. Thanks!

  8. #8
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Memory Error - Need help to optimize VBA code

    Quote Originally Posted by pgk_05 View Post
    My apologies. I wasn't aware of the cross-posting rule. [/B]
    Have you read all the forum rules then? There are not many and quite easy to understand

  9. #9
    Registered User
    Join Date
    05-18-2013
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Memory Error - Need help to optimize VBA code

    Yes, I went through the link you shared. Thank you for sharing

+ 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. VBA Code causes error: “There isn't enough memory to complete this action.”
    By dubumochi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2019, 07:30 AM
  2. VBA code error: "out of memory"
    By ToniSkulj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2018, 05:27 PM
  3. [SOLVED] Run-Time Error ‘7’: Out of Memory Issue in Code
    By Rajeshkumar R in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2017, 07:26 AM
  4. [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
  5. [SOLVED] How to optimize code? / VBA Overflow '6' Error
    By peepingtom in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-05-2013, 06:40 PM
  6. Replies: 1
    Last Post: 12-08-2011, 08:52 AM
  7. Out of Memory Error, on third line of code.
    By t0m46 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2010, 07:35 AM

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