Closed Thread
Results 1 to 21 of 21

Speed up hiding/unhiding rows

  1. #1
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Speed up hiding/unhiding rows

    Hi.

    I am using the following code to hide and unhide rows based on empty cells or cells with 0 in the B2:B81 range.

    The code works fine but is very slow. Can anyone suggest any changes to speed up the process?

    Please Login or Register  to view this content.
    Thanks for any help!

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Speed up hiding/unhiding rows

    why do you have this code:

    Please Login or Register  to view this content.
    Will some of them be hidden and you want them to unhide them?

    abousetta

  3. #3
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Yes, if there is text in the Range of cells then the row will be showing.

    Johnmus

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    See how you get on with these:
    Please Login or Register  to view this content.
    Hope that helps,

    Colin

    RAD Excel Blog

  5. #5
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Colin,

    This works great! It seems to speed up the process - Disabling Screenupdating and Calculations will help in that respect. I have one more question and I am not sure this should be a new thread.

    The macro you suggested will hide all cells with 0 or " ". The range of B4:B81 includes 6 classes of 12 groups. Each of those groups have a header 1A NAME, 2A NAME 3A NAME etc. The macro clears all empty rows, but the header is still there. Is there a way to hide the header (for example header on A29:D29) IF all cells of the 12 rows below are empty?

    Again thanks for your great suggestion!

    John

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Speed up hiding/unhiding rows

    Try this
    Please Login or Register  to view this content.
    Last edited by royUK; 03-31-2011 at 11:28 AM. Reason: tidier code
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    RoyUK

    Forgive my ignorence, but I don't see how your code would do what I need.

    I already use code to hide blank rows. See above. What I want to accomplish it is to hide the header ONLY if all 12 entries below are empty.

    For example A29 - B29 - C29 and D29 are headers

    If B30 through B42 would be empty then entire Row 29 would be hidden.

    Hope this makes sense.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Speed up hiding/unhiding rows

    The code that I can see loops through a range to hide cells, mine doesn't loop, which is much faster than a loop. It would probably be faster to use AutoFilter then a loop if there is a possibility of O values and blanks.

    Having headers within a table isn't good design, but you could check for entries in each area by using COUNTA, then hide the header row,

    You need to attach an example workbook

  9. #9
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Hi,

    I am using Colin Legg's code which seems a bit faster that the previous code (see top of Thread). Is it possible to adapt your code to include blank cells but also cells containing a Zeo ("0")?

    The range of cells is B4:B81. I am attaching a sample. The workbook inludes 11 sheets for different categories, but I am attaching just the Awards sheet.

    Thanks for your help.

    John
    Last edited by Johnmus; 04-03-2011 at 03:13 PM.

  10. #10
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    Hi John,

    The criteria I used (" " and 0) were just based on your initial post. I see that you have made some modifications to my code in the attached workbook. Before we talk about hiding division headers let me just check that the modifications are working correctly for you. For example, at the moment the code will hide Row 27, even though there is an entry in D27. Is that what you want?

  11. #11
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Hi Colin,

    No, it there is an entry in Columns B,C or D the row should NOT be hidden. The range in the code of the Awards sheet should be D4:D81 as there will be always a band, but not always Aux (C) or Perc (B) competition.

    Thanks for catching that!

    John
    Last edited by Johnmus; 04-01-2011 at 07:45 PM.

  12. #12
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    Okay, I've had a look at your worksheet and I think we can do this quite easily, but with a slightly different approach.

    In F3 I added this formula and then filled it down to F80:
    Please Login or Register  to view this content.
    In F2 I added a field header called "Hide Criteria" and I inserted a narrow row between the end of the table and the summary section area.

    I then selected cells F2:F80 and added an autofilter (so a single filter). I then hid column F so it wouldn't be an eyesore.

    I then amended the VBA code in the worksheet's class module to this:
    Please Login or Register  to view this content.
    Let us know if that suits you?

    EDIT: Amended formula.
    Attached Files Attached Files
    Last edited by Colin Legg; 04-01-2011 at 08:36 PM.

  13. #13
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Colin,

    You are brilliant! This works great. I could not get the HideRows macro you suggested at the top of the thread to work with your new macro, so I created a macro called HideRowsAwards. Is it possible to incorporate your suggestion in the old macro? Also I have a second Awards sheet in the workbook with less columns (see code below) and I modified to suit this but this is another macro HideRowsAwards1. How would I combine these two into one macro in the Module and then make Range adjustments in the Worksheet macro? Would be nice to have less macros to worry about.

    This is the macro for the Awards sheet:
    Please Login or Register  to view this content.
    This is the macro for the second Awards sheet:
    Please Login or Register  to view this content.
    As the second awards sheet has only two columns I have adjusted the formula for the second awards sheet to:

    Please Login or Register  to view this content.
    Thanks so much for your help!

    John

  14. #14
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    Hi John,
    I could not get the HideRows macro you suggested at the top of the thread to work with your new macro, so I created a macro called HideRowsAwards. Is it possible to incorporate your suggestion in the old macro?
    This suggestion entirely replaces the initial one.
    Also I have a second Awards sheet in the workbook with less columns (see code below) and I modified to suit this but this is another macro HideRowsAwards1. How would I combine these two into one macro in the Module and then make Range adjustments in the Worksheet macro?
    Please would you attach the latest file and I (or someone else) will combine them together for you. If you protect the sheets manually and allow filtering, you won't need to unprotect/protect the sheets in your code.

  15. #15
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Hi Colin,

    Attached is a sample of the two sheets. I would like to combine the two macros to activate autofilter and also be able to show the entire sheet with or without entries at the click of a button.

    Thanks again.

    John
    Attached Files Attached Files

  16. #16
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    Hi John,

    I think this is what you want?
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Hi Colin,

    This is great! That is exactly what I need. The only issue is that the Autofilter Field should be set to 6 for the Awards sheet and 5 for the AwardsPO sheet. Autofilter Field:=1 does not work. Resetting the Autofilter this will show this. Does that mean I have to create two macros?

    Also noticed that now I have #NUM! in the empty rows. Is there anyway to change that?

    Many, many thanks

    John

  18. #18
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Speed up hiding/unhiding rows

    Hi John,
    The only issue is that the Autofilter Field should be set to 6 for the Awards sheet and 5 for the AwardsPO sheet. Autofilter Field:=1 does not work. Resetting the Autofilter this will show this. Does that mean I have to create two macros?
    If you need to reset the filter then, when you reapply it, do it only for the helper column like I did. That way it will always be field 1. You could change the sub to accept an additional argument which specifies the field number but I don't really see the need.
    Also noticed that now I have #NUM! in the empty rows. Is there anyway to change that?
    Which empty rows are showing errors? When I opened your attachment I got errors in Awards-PO!A82:91 because they link to another workbook.

  19. #19
    Registered User
    Join Date
    02-10-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Speed up hiding/unhiding rows

    Hi Colin,

    OK I got it. I applied the autofilter to all columns rather than applying it to the helper column alone. I am learning ! Thank you!

    Also the #NUM! disappears after I entered a number, so no problems there.

    Really appreciate your help! I will close this thread.

    John
    Last edited by Johnmus; 04-05-2011 at 11:48 PM.

  20. #20
    Registered User
    Join Date
    10-21-2014
    Location
    Belgium
    MS-Off Ver
    MS office 2013
    Posts
    3

    Re: Speed up hiding/unhiding rows

    Hi,

    is there a way to apply the below code to all selected tabs?

    Thank you





    Quote Originally Posted by Colin Legg View Post
    See how you get on with these:
    Please Login or Register  to view this content.

  21. #21
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Speed up hiding/unhiding rows

    Pls start your own thread as per forum rules.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed 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