+ Reply to Thread
Results 1 to 10 of 10

How to stop Screen Flickering when Code Hides and Unhides Rows

Hybrid View

  1. #1
    Registered User
    Join Date
    01-03-2013
    Location
    Hartford CT
    MS-Off Ver
    Excel 2010
    Posts
    20

    How to stop Screen Flickering when Code Hides and Unhides Rows

    I already tried the

    Application.ScreenUpdating = False
    
    'My Code
    
    Applications.ScreenUpdating = True
    Here is my complete code so you get an idea of what is happening:

    Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
      
      Application.ScreenUpdating = False
    
    
    
        Dim slItem As SlicerItem
        Dim slCache As SlicerCache
        Dim NumVal As Double
        Dim AcctManagerNm As String
        Dim rng As Range
        Dim x As Long
        
    Worksheets("OfficeScoreCard").Range("E15:E767").EntireRow.Hidden = False
    Worksheets("OfficeScoreCard").Range("E18:E767").ClearContents
    
    Set rng = Worksheets("OfficeScoreCard").Range("E15")
    Set pt = Target
    Set pt = Worksheets("Data").PivotTables("pvt_Census")
    Set slCache = ActiveWorkbook.SlicerCaches("Slicer_EmployeeNm1")
    
    
    With slCache
            For Each slItem In .VisibleSlicerItems
                If slItem.HasData = True Then
                    AcctManagerNm = slItem.Name
                    NumVal = pt.GetPivotData("Count of EmployeeNm", "EmployeeNm", AcctManagerNm)
                    If NumVal > 0 Then
                        x = x + 3
                        rng.Offset(x, 0).Value = AcctManagerNm
                    End If
                End If
            Next
        End With
        
    
    Worksheets("OfficeScoreCard").Range("E" & x + 18 & ":E767").EntireRow.Hidden = True
    
    
    Application.ScreenUpdating = True
    
    
    
    End Sub
    Thanks in advanced!

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    hi there, try this as a guess:

    Application.ScreenUpdating = False
    Application.EnableEvents=False
    
    'My Code
    
    Application.EnableEvents=True
    Applications.ScreenUpdating = True

  3. #3
    Registered User
    Join Date
    01-03-2013
    Location
    Hartford CT
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    Quote Originally Posted by watersev View Post
    hi there, try this as a guess:

    Application.ScreenUpdating = False
    Application.EnableEvents=False
    
    'My Code
    
    Application.EnableEvents=True
    Applications.ScreenUpdating = True
    Thanks for the guess but I already tried that as well...no dice!

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    any chance to get the sample file which has that flickering event?

  5. #5
    Registered User
    Join Date
    01-03-2013
    Location
    Hartford CT
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    Quote Originally Posted by watersev View Post
    any chance to get the sample file which has that flickering event?
    still new to the forums How do I attach the excel document? and is 10mb too large to attach?

    Thanks,

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    Zipped archive and .xlsb files have allowance of 9.77 MB, for the others - 1 MB.

    To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  7. #7
    Registered User
    Join Date
    01-03-2013
    Location
    Hartford CT
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    The file should now be attached so you can see what is going on.

    Thanks!
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    you might not need those Application stuff anymore

  9. #9
    Registered User
    Join Date
    01-03-2013
    Location
    Hartford CT
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    Ended up finding this and applying it to my code and it worked!!

    http://www.excelforum.com/excel-prog...dowupdate.html

    Here is my complete code for reference:

    Private Declare Function LockWindowUpdate Lib "user32" _
      (ByVal hwndLock As Long) As Long
    
    
    Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
      LockWindowUpdate Application.Hwnd
      Application.ScreenUpdating = False
    
      Application.EnableEvents = False
     
      
        Dim slItem As SlicerItem
        Dim slCache As SlicerCache
        Dim NumVal As Double
        Dim AcctManagerNm As String
        Dim rng As Range
        Dim x As Long
        
        
        
    Worksheets("OfficeScoreCard").Range("E18:E767").ClearContents
    
    Set rng = Worksheets("OfficeScoreCard").Range("E15")
    Set pt = Target
    Set pt = Worksheets("Data").PivotTables("pvt_Census")
    Set slCache = ActiveWorkbook.SlicerCaches("Slicer_EmployeeNm1")
    
    
    With slCache
            For Each slItem In .VisibleSlicerItems
                If slItem.HasData = True Then
                    AcctManagerNm = slItem.Name
                    NumVal = pt.GetPivotData("Count of EmployeeNm", "EmployeeNm", AcctManagerNm)
                    If NumVal > 0 Then
                        x = x + 3
                        rng.Offset(x, 0).Value = AcctManagerNm
                    End If
                End If
            Next
        End With
        
    
      
    Worksheets("OfficeScoreCard").Range("E15:E767").EntireRow.Hidden = False
       Worksheets("OfficeScoreCard").Range("E" & x + 18 & ":E767").EntireRow.Hidden = True
        
        
    Application.ScreenUpdating = True
     
    Application.EnableEvents = True
        
    LockWindowUpdate ByVal 0&   'simply passing a long value of 0 into the function
        
        
    End Sub

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to stop Screen Flickering when Code Hides and Unhides Rows

    yes, I see what you mean. I'll need some time to think of the way to avoid it. Will post back latest tomorrow evening if it's OK with you.

    Good point

+ 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 code to stop screen from flickering does not work
    By joy_ in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-12-2012, 11:30 AM
  2. [SOLVED] Macro code that hides or unhides rows in other worksheets
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2012, 04:10 PM
  3. Screen flickering. Too much code?
    By MarcoAUA in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-05-2012, 12:14 AM
  4. Userform that hides/unhides worksheets
    By fecurtis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-20-2008, 09:36 AM
  5. [SOLVED] Button hides unhides columns, how?
    By JimH in forum Excel General
    Replies: 3
    Last Post: 04-20-2005, 05:06 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