+ Reply to Thread
Results 1 to 8 of 8

Simple macro takes a long time to execute

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Simple macro takes a long time to execute

    Hello!

    I have a small problem with a simple macro that I have assigned to a button. The thing is: I just want it to hide empty rows. This works perfectly, but running the program on 200 rows takes about 15 seconds to run, which seems incredibly long to me.

    I was wondering if I made a mistake in the macro, or is there a way to make it much... lighter?

    Thank you in advance,

    Carel


    Please Login or Register  to view this content.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Simple macro takes a long time to execute

    Hi Carel,
    try this
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Simple macro takes a long time to execute

    Ah that worked perfectly, it runs like a charm now! Thank you very much, I'm going to examine that bit of code!

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Simple macro takes a long time to execute

    Instead of loop rather use SpecialCells:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Simple macro takes a long time to execute

    Hi zbor, thanks!

    It did not work, though, maybe because all cells are filled with formulas, and thus not seen as Blank Cells?

  6. #6
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Simple macro takes a long time to execute

    Quote Originally Posted by nilem View Post
    Hi Carel,
    try this
    Please Login or Register  to view this content.
    nilem, I almost completely understand the code you wrote, except for the intersect part: I am trying to use the same code for another sheet to do exactly the same, but then to hide columns based on values in a row, instead of the other way around. I thought switching the RowIndex and ColumnIndex in the Cells() would solve it already, but I'm getting an error in the Intersect-line.

    edit: nevermind, I forgot to change Columns into Rows... Thank you!
    Last edited by jcfransen; 01-11-2015 at 04:10 AM.

  7. #7
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Simple macro takes a long time to execute

    Everything works great, but I still ran into one tiny problem:

    If, due to a formula in one of the hidden cells, the value of the cell changes from 0 to a higher value, I'd like that - if I run the macro - this row is unhidden. However, this does not seem to work with this code - it just hides columns that are not yet hidden, and not the other way around. Any idea how to make that work?

    Thanks!

  8. #8
    Registered User
    Join Date
    03-08-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Simple macro takes a long time to execute

    Alright, solved that as well. Everything works fine. Thank you very much for your assistance nilem and zbor!

    The final code that I used:

    Please Login or Register  to view this content.

+ 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] Adding Checkboxes, But Macro still takes too long to execute
    By Bob1980 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-21-2014, 01:17 PM
  2. VBA takes too long to execute..
    By ruchi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2009, 04:53 AM
  3. My Code takes too long to execute
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2008, 12:12 AM
  4. how do i add time to see how long my macro takes to run
    By ernestgoh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2006, 06:10 AM
  5. Time Calculation - How long a macro takes to run
    By cdb in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-31-2005, 04:06 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