+ Reply to Thread
Results 1 to 11 of 11

Clunky Slow Code, Hides Empty Rows, Takes too long...

  1. #1
    Registered User
    Join Date
    11-08-2013
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2010
    Posts
    25

    Clunky Slow Code, Hides Empty Rows, Takes too long...

    Hello, I've written code that hides rows on different sheets if they are empty and in one case changes column width to keep the formatting looking ok. I've used non-contiguous named ranges because there are multiple places on each row that could (or could not) be empty. It does exactly what I want, but it takes a long time to process and will only get longer if I continue to add new sheets. I'm pretty new to VBA, but I know I didn't write it well as I am iterating through multiple ranges and performing tests on each cell. I'm pretty sure I could use an array, but I failed at coding that myself. Moreover, using xlspecialcellblanks isn't working, because the "empty" cells have formulas in them. Any help would be greatly appreciated! Thanks very much.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Try replacing:
    Please Login or Register  to view this content.

    with:
    Please Login or Register  to view this content.

    Any better?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Ah - ignore my post, I just read your post PROPERLY Silly me!

  4. #4
    Registered User
    Join Date
    11-08-2013
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Oh well, thanks for trying anyways. I was thinking maybe there was an array solution, so I could reference the array index instead of each cell but I don't know how to do it. I know I could get the range to be hidden set dynamically to a variable but then I couldn't get the column width part to work too.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Hi

    try this code.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Brilliant Question by the way. It got me thinking.

    This will un-hide rows that contain numbers or text, whether they are constants or returned by a formula.

    No loops are involved.

    Enjoy.

  7. #7
    Registered User
    Join Date
    11-08-2013
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Hi mehmetcik,

    Thanks so much for your reply! Unfortunately, I want to hide rows that have formulas (or references) but are returning blanks due to no input in the reference cell. Your code unhides these which are a reference to empty cells. I tried IF(ref="","",ref) in the cells as well and still no dice. I think that is why the "Empty" property has worked in my code. I think I may have to set the area to be hidden first by a loop and then hide that. I'm really new with arrays, and I got one that seems to iterate through an index of cells, but for some reason (even though I can see it has the correct reference in debug) it doesn't recognize the cell... maybe I need to redim the array, but again, I am inexperienced with them.

  8. #8
    Registered User
    Join Date
    11-08-2013
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    For Example, I use the following code and I can see the varray referencing cells it should be unhiding... but, it doesn't unhide them as my original For...Each loop would...
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Hi

    All you have to do is to hide the formulas returning blanks I would have thought.

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Hi

    All you have to do is to hide the formulas returning blanks I would have thought.


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-08-2013
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Clunky Slow Code, Hides Empty Rows, Takes too long...

    Thanks again for your response! Oddly enough, this code works but only if my formulas have the IF(ref="","",ref) convention, but unfortunately, it puts me back in the same position of iterating through many cells and the time it takes to process is about the same as my original code. I'm not sure if you were referring to hiding the formulas (as in protect sheet) or just hiding 0s... I'm also not sure why your first code didn't work but it did with the FOR EACH loop. I even tried defining the ranges.

    I actually did get my array solution to check the IF<>EMPTY condition based on array index but then I run into another issue: using Union to join two non-contiguous ranges. Which is why in the following code I had to dim my array as A:C and then of course in the scope of things I am once again not speeding up the process very much. This has been a difficult one for me.
    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. VBA that hides rows with 0 takes FOREVER to run
    By Sky188 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-28-2013, 04:04 PM
  2. [SOLVED] Worksheet Macro that hides empty rows does not work
    By Taktiker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-22-2012, 11:11 AM
  3. Long code takes an age to run
    By E3iron in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-05-2009, 07:38 AM
  4. 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
  5. macro that hides rows run slow
    By yoav_b in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-15-2007, 11:16 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