+ Reply to Thread
Results 1 to 11 of 11

Stuck with slow macro - Hide rows and auto fit

  1. #1
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Stuck with slow macro - Hide rows and auto fit

    Dear all, I've been reading this forum for quite some time now and every time the forum helped me solve my excel of VBA problem. Except this time.

    I have a problem with the speed of the following macro:

    Please Login or Register  to view this content.
    The macro should kick in when field E2 is changed (based on a validated list).

    My sheet consists of aprox 600 rows. The sheet processes a report where some of the rows should be hidden and all non-hidden rows should be auto fitted.

    'Column A' is blank of filled with an "X". All rows with a blank cell in 'column A' should be hidden, all other should be shown.
    'Columns AJ to AO' are used to auto fit the rows. These columns are adjusted to the length of specific merged columns, since auto fit doesn't work on merged cells/colums.

    The main problem: it takes about 15 to 20 seconds to process hide/show and auto fit. It shouldn't take this long, but I've been tinkering with this macro several times now, without much result. Any advice?

    Thanks in advance! Regards, D.

    Edit: I have used the search function (and googled ofc) but I can't get some of the alternatives to run. I only have basic VBA knowledge.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Stuck with slow macro - Hide rows and auto fit

    Try:

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Re: Stuck with slow macro - Hide rows and auto fit

    Quote Originally Posted by walruseggman View Post
    Try:
    Thanks! It does work a lot quicker, however, it unfortunately only works on totally blank cells.
    The cells in column A have a small formula in them like: =IF(D100="";"";"X") to determine whether or not the row should be hidden.

    Is there a workaround for this?

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Stuck with slow macro - Hide rows and auto fit

    Well since your formula is looking to see if D is blank, can't you just change the code to look at column D, and therefore not even need the X's in column A?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Re: Stuck with slow macro - Hide rows and auto fit

    That won't work. A cell in column A doesn't always have to correspond with the cell in column D on the same row. Eg: Cell A1 could check contents for cell D2.

    A1 (Cell D2="") - Row 1 Should be hidden
    A2 (Cell D2="") - Row 2 Should be hidden
    A3 (Cell D2="") - Row 3 Should be hidden
    A4 (Cell D5="text") - Row 4 should be shown
    A5 (Cell D5="text") - Row 5 should be shown

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Stuck with slow macro - Hide rows and auto fit

    Then try this. Won't be as fast as my last approach, but should be faster then your original code. Would be interested to know how long it takes to run on your data set.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Re: Stuck with slow macro - Hide rows and auto fit

    I appreciate your help, thanks
    The code works but bugs on the following line
    Please Login or Register  to view this content.
    As for runtime:
    Original macro (TS Post): 19,31 sec
    Post #6 macro: 18,9 secs

    Would it be a solution to populate a specific column (eg column AC) with a 1 or a 2 based on the X in column A? (or edit the formulas in column A to give a 1 or a 2). Would that make it possible to use the lightning fast macro you gave before?

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,362

    Re: Stuck with slow macro - Hide rows and auto fit

    How about this one ?
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Re: Stuck with slow macro - Hide rows and auto fit

    It works without any errors, however, runtime is still 19,39 seconds for each cycle.

    I suspect the 'Next' cycle is making it go slow, correct?

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,362

    Re: Stuck with slow macro - Hide rows and auto fit

    Post a small example workbook which reflects actual situation so we have something to work with.
    I've made an example workbook myself with formula like Post #3 and it evaluates 600 formulas and hides rows in 0.1 sec so something else must be going on.

  11. #11
    Registered User
    Join Date
    03-01-2016
    Location
    Netherlands
    MS-Off Ver
    14.5.8 (OSX)
    Posts
    6

    Re: Stuck with slow macro - Hide rows and auto fit

    Sorry for my absence, holiday.

    Thanks for the explanation. I will try to post an example workbook next week!

+ 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] Macro to Hide Zero Total Rows Runs VERY Slow
    By Mr.Nick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2015, 09:55 PM
  2. Macro/VBA for auto hide unhide rows
    By louvaek in forum Excel Programming / VBA / Macros
    Replies: 53
    Last Post: 11-29-2014, 05:36 PM
  3. Macro to auto hide rows in a specific range
    By morayman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2014, 10:03 AM
  4. Macro to hide rows to slow
    By mort.marshall.20 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-15-2013, 12:47 PM
  5. [SOLVED] Macro To Auto-Hide Rows
    By TheRustyScupper in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2013, 02:01 AM
  6. Need Macro to Auto hide rows
    By cmwood in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2013, 10:47 AM
  7. Macro for auto format hide columns rows??
    By txjackknife in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2009, 01:39 PM

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