+ Reply to Thread
Results 1 to 11 of 11

Faster macros for hiding/unhiding rows?

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    10

    Faster macros for hiding/unhiding rows?

    Hello,

    I'm pretty new to VBA, so please forgive me if this is a noob question. I've been researching online for macros that will hide rows if certain cells in them are blank or 0, and then I've created macros to unhide those same rows again. I've found some that work for me -- the only problem is that the macros run quite slowly in some spreadsheets. I will post the macros I'm using below; would you please let me know if you see anything that could be adjusted to make them faster, or if you know of a more efficient macro which would accomplish this?

    Hide Empty Rows
    Please Login or Register  to view this content.
    Unhide Rows
    Please Login or Register  to view this content.
    Thank you so much for your help!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Faster macros for hiding/unhiding rows?

    How is the code slow when it loops only from intStartRow = 11 intEndRow = 28?
    You are not looping through thousands rows.
    Filering code is supposed to be fast

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Faster macros for hiding/unhiding rows?

    I appreciate your help with this!

    It may be that the answer to my question is I need a faster computer (my machine is pretty old), or that I have an unrealistic expectation of the speed I should be seeing. It definitely doesn't seem fast to me... it takes about 4 seconds for the code to loop through row 11-28.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Faster macros for hiding/unhiding rows?

    Try this one. I cut out some of the lines

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Faster macros for hiding/unhiding rows?

    it takes about 4 seconds
    You meant 40 seconds.
    I think 4 seconds is normal time for any VBA code to run

  6. #6
    Registered User
    Join Date
    02-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Faster macros for hiding/unhiding rows?

    Thank you, that's good to know. No, I meant 4 seconds. The other macros I'm running all run in under a second, so it seemed like these are slow by comparison.

    I tried using your compressed code but it did not work for me.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Faster macros for hiding/unhiding rows?

    Hi Teaorchid

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed. Please explain what it is you wish to do.

    Include in the attachment any code you're currently using (whether it works or not) and, if appropriate, an "After" worksheet that demonstrates what you wish the output to be.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the "Upload Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Faster macros for hiding/unhiding rows?

    Are the empty values are zero, or no value? If they are zeros, try this line

    Please Login or Register  to view this content.
    Last edited by AB33; 02-22-2013 at 07:32 PM.

  9. #9
    Registered User
    Join Date
    02-19-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Faster macros for hiding/unhiding rows?

    After trimming the document of proprietary information in order to create a sample file, it seems to be running faster, so the problem may just be that it's an unwieldy spreadsheet, with lots of formulas tying to other tabs. However, I have attached the sample file for your thoughts.

    Thanks again for your help with this!
    Attached Files Attached Files

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Faster macros for hiding/unhiding rows?

    Hi Teaorchid

    Add the indicated lines of Code to each of your Procedures
    Please Login or Register  to view this content.
    Last edited by jaslake; 02-22-2013 at 10:34 PM.

  11. #11
    Registered User
    Join Date
    02-19-2013
    Location
    Sri Lanka
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    71

    Re: Faster macros for hiding/unhiding rows?

    Hi Teaorchid,

    I just checked your sample attached document.
    If you add "Application.ScreenUpdating = False" at the beginning of the code
    and at the last you write Application.ScreenUpdating = True.

    When u don't add this code in your macro, application may run little bit of slow.

    http://excelsenior.com/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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