I have a simple sub-routine that I am using to check if the active worksheet has frozen panes, if it does, it gives the user the option to unfreeze or exit. If there are no frozen panes when the routine is run, it is supposed to select the second row and then freeze panes so that the "header" row remains visible.
Sub FreezePanesHeaders() Dim SaveSelection As Range Application.ScreenUpdating = False Set SaveSelection = Selection On Error GoTo Errhandler: If ActiveWindow.FreezePanes = True Then If MsgBox("Panes Already Frozen! Do you want to Unfreeze?", vbYesNo, "Freeze Panes") = vbYes Then ActiveWindow.FreezePanes = False Application.ScreenUpdating = True Exit Sub Else Application.ScreenUpdating = True Exit Sub End If End If If ActiveWindow.FreezePanes = False Then ActiveSheet.Select Rows("2:2").Select ActiveWindow.FreezePanes = True End If SaveSelection.Select Errhandler: Application.ScreenUpdating = True End Sub
For some reason, which I have not been able to identify, or reliably replicate, every so often the routine will ignore the "Rows("2:2").Select" portion of the code, and just freeze the panes in the middle of the active window. There are no hidden columns, no merged cells. Anyone run in to this before?