Here is a much better solution, for fixing simultaneously both the
Excel(main chart) "flickering" & Userform "repainting" situations.
The VBA code shown below, can be placed into any Userform(panel).
Option Explicit
'=================================
'-Variable indicating whether
'- "cascading" is (True) or (False).
'-This would be placed in the
'-declaration section of the module.
'=================================
Public frmCASCADE As Boolean
The subsequent procedure( PCascade ), can be placed into any workbook module.
Sub PCascade ( )
Application.ScreenUpdating = False
frmCASCADE = True
End Sub
'===============================================
'-The following examples shows when calling the above
'-procedure(PCascade) to "optimize" performance and
'- also sets the global variable(frmCASCADE) to (True).
'===============================================
Private Sub SpinButton1_SpinDown()
Call PCascade
'=================================
'-Other VBA code to be executed.
'=================================
'...
'...VBA Code
'...
'=================================
'-Control is returned back to the user.
'=================================
End Sub
Private Sub SpinButton2_SpinUp()
Call PCascade
'=================================
'-Other VBA Code to be executed.
'=================================
'...
'...VBA Code
'...
'=================================
'-Control is returned back to the user.
'=================================
End Sub
'==========================================
'-Solution Code is shown below for any Userform.
'==========================================
Private Sub UserForm_Initialize()
frmCASCADE = False
Cascade.StartUpPosition = 0
Cascade.Top = (Application.Height / 8) - (Cascade.Height / 8)
Cascade.Left = (Application.Width - Cascade.Width) / 2
End Sub
Private Sub UserForm_Layout()
'======================================
'-Each time when Userform(panel) is
'-moved/slid around on the screen,
'-this code is reexecuted each time.
'-Therefore, check the global variable
'-(frmCASCADE) is ( True ), which
'-indicates that this Userform(panel)
'-is in cascading mode.
'======================================
If frmCASCADE Then
'================================================
'-Then reset the screen to prevent the cascading
'-of this Userform(panel). Also, reset global
'-variable(frmCASCADE) to (False), so next time
'-when this Userform(panel) is moved, this code
'-is not rexecuted again, until the (frmCASCADE)
'-variable is set to (True) again.
'================================================
Application.ScreenUpdating = True
frmCASCADE = False
End If
End Sub