+ Reply to Thread
Results 1 to 9 of 9

Excel VBA Worksheet Calculate running slowly

  1. #1
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Excel VBA Worksheet Calculate running slowly

    Hello all,

    My question pertains to the Worksheet_Calculate VBA sub. I have the code below that I wish to execute every time a cell is "confirmed" within the worksheet.

    Basically, I have the table range that spans columns A:I, with various field headers. Column A has numbers that either contain integers or values with decimals in them. The current code cycles through column A, and if the cell value contains a decimal, it is formatted as white fill with black bordering and font. If it does not contain a decimal, it is formatted as blue fill with white font, etc.

    The current code works, but is very slow to run. I am hoping for some guidance on getting a more consolidated/streamlined block of code for this...something that may include a "For Each Cell in Rng" loop?

    Any help is appreciated!

    Please Login or Register  to view this content.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,911

    Re: Excel VBA Worksheet Calculate running slowly

    How slow is slow to run?
    I just put the code into a workbook with some dummy data and it ran practically instantly on 10,000 rows of data.

    It could be that there's nothing wrong with the code but something else in your workbook is slowing things down.
    Impossible to say without sight of the workbook I'm afraid.

    BSB

  3. #3
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Excel VBA Worksheet Calculate running slowly

    Very strange. Perhaps it's my machine...I just placed the code into a dummy workbook as well and ran it on <300 rows and still slow to respond (took 5 seconds for 22 rows before I ended it). Appreciate you taking a look nonetheless!

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,911

    Re: Excel VBA Worksheet Calculate running slowly

    Mine took less than 4 seconds to do all 10k rows and that's on a laptop that has seen better days and is far from high spec!

    BSB

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Excel VBA Worksheet Calculate running slowly

    Hi,

    Have you tried using conditional formatting instead?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Excel VBA Worksheet Calculate running slowly

    Quote Originally Posted by xlnitwit View Post
    Hi,

    Have you tried using conditional formatting instead?
    I have tried; it works, but I'm hoping to go the VBA route for easier maintenance on my end - especially since I've had hard times in the past with conditional formatting and adding new rows/columns to my range.

    Attached is a sample workbook that I'm hoping I've desensitized enough. If you guys aren't able to replicate the slow churn, then I'll know it's my machine. Otherwise, please feel free to tear apart my code
    Attached Files Attached Files

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Excel VBA Worksheet Calculate running slowly

    It is definitely slow here! I think this will be faster though there will still be a lag
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Excel VBA Worksheet Calculate running slowly

    Not a long lag time at all, thanks! Any insight as to what may have been bogging down the previous code?

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Excel VBA Worksheet Calculate running slowly

    Formatting one row at a time is slower than formatting blocks of ranges at once.

+ 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. Help my code is running very slowly..
    By wishmaker in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-06-2014, 06:03 AM
  2. VBA Code is running really slowly
    By behrensf84 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2014, 06:06 PM
  3. Code running really slowly
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2014, 08:42 PM
  4. [SOLVED] Code running slowly
    By Sweepin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2013, 09:15 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. Code running slowly
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 02-01-2011, 11:08 AM
  7. Macros in Excel 2000 running very slowly
    By cottage6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2005, 06:06 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