+ Reply to Thread
Results 1 to 7 of 7

Why is my macro running slowly?

  1. #1
    Registered User
    Join Date
    11-26-2013
    Location
    .
    MS-Off Ver
    Excel 2010
    Posts
    33

    Why is my macro running slowly?

    Hi everyone.

    I'm trying to run a basic simulation supported by the below macro. The purpose of the macro is to effectively copy and paste 45 values generated in row 18 (which are tied to rand() formula cells and thus change with each update) and paste them into a table starting from row 23 and with a table-depth as defined in cell B3. The intention is that once the 45 values in row 18 have been copied into row 23, the values in row 18 update and these new values are then then pasted into row 24 and so forth until the number of rows in cell B3 has been reached. I also have a helper cell that counts the number of rows generated, so I when I run the macro I can see how much progress has been made before putting the kettle on.

    My question is: when I run the macro I can see the values being generated in row 18 updating multiple times per second, but the number of rows being counted (by the helper cell) in my table progresses at a much slower rate. It looks as though multiple "iterations" are occurring per row update, but (accepting my very basic experience with VBA) I can't see why that would be. Is there anything I'm doing wrong?

    Thanks for any help

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2404-17531.20128
    Posts
    1,361

    Re: Why is my macro running slowly?

    My guess would be that it is caculating every RandBetween formula everytime it writes one value to the worksheet, you can get around this by switching off automatic calculation and then calulate when you wish to then' at the end switch it back to automatic as below:
    Please Login or Register  to view this content.
    You could just put the rand between part straight into the code as below but this man not suit your needs:
    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Why is my macro running slowly?

    I'd also suggest that since you appear to have blocks being copied, you don't write cell by cell as that will be a lot slower. You can do something like:

    Please Login or Register  to view this content.
    and then factor in the recalculation wherever you want it.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2404-17531.20128
    Posts
    1,361

    Re: Why is my macro running slowly?

    Or write to the sheet only once:
    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.
    The above will lose any formula you have in the gaps in the columns - they would be reaplced with values - not able to see if this will be an issue as we can't see the real data and layout.
    Last edited by CheeseSandwich; 03-28-2022 at 07:04 AM. Reason: Added note

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Why is my macro running slowly?

    Quote Originally Posted by CheeseSandwich View Post
    The above will lose any formula you have in the gaps in the columns
    You could avoid that by reading/writing the Formula property rather than the Value.

  6. #6
    Registered User
    Join Date
    11-26-2013
    Location
    .
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Why is my macro running slowly?

    Thanks very much both, I will try and incorporate.

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2404-17531.20128
    Posts
    1,361

    Re: Why is my macro running slowly?

    Quote Originally Posted by rorya View Post
    You could avoid that by reading/writing the Formula property rather than the Value.
    Good point rorya: Every day is a school day...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 03-28-2022 at 07:57 AM.

+ 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] Macro's running slowly
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-08-2020, 05:23 AM
  2. Code running v slowly when Called from another Macro
    By theo499 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2019, 10:39 AM
  3. Macro running slowly when executed from the VBA Editor
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2017, 09:18 AM
  4. [SOLVED] Simple macro to hide rows running very slowly
    By mbp727 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2013, 02:37 PM
  5. [SOLVED] Formatting sheets with macro running very slowly
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-21-2012, 10:04 AM
  6. Recorder created Macro running slowly
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-19-2010, 03:17 PM
  7. macro running slowly (file size related???)...
    By sunilmulay in forum Excel General
    Replies: 4
    Last Post: 10-22-2008, 10:41 PM

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