0
votes

I recorded a macro to freeze panes, but it is not working as intended. It freezes at the 2nd row and makes the top row hidden. Help. I am using Excel 2007. The code is below:

' Freeze Pains - Top Row

With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
End With
ActiveWindow.FreezePanes = True
1
Worked for me on 2013.findwindow
Does it matter which cell is active when this is run?Iron Man

1 Answers

2
votes

I found this code works perfectly:

Sub Freeze_Top_Panes()
   Application.ScreenUpdating = False

   Rows("2:2").Select
   ActiveWindow.FreezePanes = True

   Application.ScreenUpdating = True

End Sub

To achieve this for all sheets in your workbook, try this:

Sub Freeze_All()
Dim Ws As Worksheet
Application.ScreenUpdating = False
For Each Ws In Application.ActiveWorkbook.Worksheets
    Ws.Activate
    With Application.ActiveWindow
        .FreezePanes = True
    End With
Next
Application.ScreenUpdating = True
End Sub

Ii am not sure if this only affects Excel 2007 (as I have not tested it on other versions yet), but it appears that you must turn off screen updating for the freeze panes function to work with VBA. Not sure as to why that is.