Mac – Freeze multiple columns in excel using macro

macrosmicrosoft-excel-2010vba

Under the Freeze panes, Excel currently offers Freeze panes, Freeze first row and Freeze first column options.
I was looking for an option where I can freeze the first N-columns.
I did a record macro to find out what Excel was doing when Freeze first column option was selected and it showed this:

Sub Macro1()
' Macro1 Macro
    With ActiveWindow
        .SplitColumn = 1
        .SplitRow = 0
    End With
    ActiveWindow.FreezePanes = True
End Sub

But what actually is happening is a split column than the freeze pane function.

So when I changed the .SplitColumn=4, I ended having a split than freeze panes.

Is there a workaround for this or is this suppose to work only this way?

Best Answer

This is an interesting question, and I can see your question is actually 2 parts.

  1. Why does the macro choose Split instead of Pane and
  2. How to work around it.

I don't know the answer to 1, so I'll focus on 2 only.

Since you want to unfreeze you need to use freeze!

Sub DoThis()

    Columns("E:E").Select
    ActiveWindow.FreezePanes = True

End Sub
Related Question