Question

I have made an excel with multiple sheets. Some of the sheets have VBA code. When I try to hide / unhide sheets, it sometimes freezes excel. When I run any routine in VBA (opened in a separate window), it becomes normal. I can't understand why excel freezes.

Update

I had not posted any code earlier as I thought it is something generic, since I believed no code was executed in hiding / unhiding sheets. I have figured out the problem. I had the following code in the worksheet_activate event in a worksheet. I believe it is the
"Application.screenUpdating = False" which was causing the issue.

The problem happened when I was trying to hide some other sheet such that this sheet would become active, or when I was trying to unhide this sheet.

Private Sub Worksheet_Activate()

'Application.ScreenUpdating = False

Dim c As Range

'show relevant fields
For Each c In Range("hide")
If c.Value = "hide" Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next

End Sub

No correct solution

OTHER TIPS

Using Application.ScreenUpdating = False is OK and even recommended in a lot of situations, but you need to be sure that you set it back to True:

Application.ScreenUpdating = False
'...
'do some operations that will cause 
'the screen to flash, like opening 
'lots of files or manipulating ranges
'on active sheet
'...

Application.ScreenUpdating = True
'...
'not worried about screen updates anymore
'...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top