Freeze Panes - VBA - Sometimes Ignoring Selection

  • Hi there,


    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.



    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?

  • Re: Freeze Panes - VBA - Sometimes Ignoring Selection


    Instead of using Select try using Application.Goto.

    Code
    If ActiveWindow.FreezePanes = False Then
        
            Application.Goto ActiveSheet.Range("A1"), True
            Application.Goto ActiveSheet.Rows("2:2"), False
            ActiveWindow.FreezePanes = True
        End If

    Boo!:yikes:

  • Re: Freeze Panes - VBA - Sometimes Ignoring Selection


    Hi Norie,


    This seems to be working, but like I said I haven't been able to reliably replicate the issue, so will have to continue testing/using to see if it comes up with the same issue or not again.


    Do you know why your method would yield the better result, or posed differently, do you know what the flaw is with my initial method?


    Thanks!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!