How do I freeze panes using VBA?

Freezing panes in Excel using VBA involves working with the `ActiveWindow` object. Here is a step-by-step guide to freeze panes using VBA:

1. Open the Excel workbook where you want to freeze panes.
2. Press `Alt + F11` to open the VBA Editor.
3. Go to `Insert > Module` to insert a new module.
4. In the module window, you can use the following VBA code to freeze panes:



Sub FreezePanes()
' Freeze the top row
ActiveWindow.SplitRow = 1
ActiveWindow.FreezePanes = True
End Sub



5. Press `F5` or `Run > Run Sub/UserForm` to execute the code.
6. Now, the top row in your Excel sheet will be frozen.

You can modify the code to freeze panes at a specific row or column by changing the values accordingly. For example, to freeze the first column, you can use `ActiveWindow.SplitColumn = 1`.

Remember to save your workbook as a macro-enabled file (`.xlsm`) if you want to keep the VBA code for freezing panes.
How do I freeze panes using VBA?

Related Questions