+ Reply to Thread
Results 1 to 6 of 6

Simple Script to hide rows - runs slow

  1. #1
    Registered User
    Join Date
    03-21-2014
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Simple Script to hide rows - runs slow

    Hi folks! I have been searching the forum for a solution to this problem, but I'm stumped. I have a simple code that that hides a range of rows if a script is called. The script "CallCompConv" is called if a selection is made on a drop down menu. The problem is, it hides the rows just fine, but stalls for 30 seconds to a minute! I'm stumped, because it all seems like a simple script! I have heard that scripting it with autofilter may work better, but I have not been able to find that code. Any help would be greatly appreciated!

    Sub CallCompConv()

    Application.ScreenUpdating = False
    ActiveSheet.DisplayPageBreaks = False
    Application.EnableEvents = False
    ActiveWorkbook.Sheets("Customer Setup").Activate

    ActiveSheet.Rows("51:57").EntireRow.Hidden = True
    ActiveSheet.Rows("46:50").EntireRow.Hidden = False

    ActiveSheet.DisplayPageBreaks = True
    Application.EnableEvents = True
    Application.ScreenUpdating = True

    End Sub
    This is the code that the dropdown uses to call the code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A35")) Is Nothing Then
    Select Case Range("A35")

    Case "Competitive Conversion"
    Call CallCompConv

    Case "New Location Bodyshop"
    Call CallNewLoc

    Case "Existing Bodyshop"
    Call CallExistingBS

    Case "New Jobber"
    Call CallNewJobber

    Case "Existing Jobber"
    Call CallExistingJobber

    End Select
    End If

    End Sub

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Simple Script to hide rows - runs slow

    a couple of things....

    Turn autocalculation off while doing this....there might be a lot of calculations happening.

    my real guess is that everytime the system "hides" a row it re-runs the Worksheet_change() so it's taking time to run this worksheet_change over and over....

    you can step throught the code and watch to see if that's what happening...

    HTH
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    03-21-2014
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Simple Script to hide rows - runs slow

    Thanks! If that is the case (running the worksheet_change over and over), any tips on how to stop that or move the "call" script to a different location?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Simple Script to hide rows - runs slow

    Would this be an option? Rather than calling the subs incorporate the action in your event?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-21-2014
    Location
    Michigan, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Simple Script to hide rows - runs slow

    Unfortunately it is just as slow doing it that way. Thanks though!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Simple Script to hide rows - runs slow

    my real guess is that everytime the system "hides" a row it re-runs the Worksheet_change()
    Can't see why that would cause the event handler to run. It's not changing the value of a cell. If there are SUBTOTALs, that might cause a calculation.

    Are there any formulae that use whole column or whole row cell references?

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Worksheet_Change(ByVal Target As Range) to hide rows is very slow!
    By AttalaEA in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-09-2017, 12:12 PM
  2. 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
  3. Script doesn't work anymore (auto hide rows and columns
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2013, 02:17 AM
  4. [SOLVED] Hidding Rows Macro Runs Very Slow
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-13-2012, 10:55 AM
  5. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 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