Freeze Panes in Excel

The code example above shows how to create a freeze pane, locking rows and columns in place, allowing them to remain visible while scrolling. It is a very useful feature to keep the header column or row in place while quickly comparing information.

CreateFreezePane(column, row)

The first CreateFreezePane method overload takes the column and row amount to create a freeze pane based on it. For example, workSheet.CreateFreezePane(1, 4) will create a freeze pane from column(A) and rows(1-4).

CreateFreezePane(column, row, subsequentColumn, subsequentRow)

This overload creates a freeze pane based on the column and row amount provided as well as applies scrolling to the worksheet. For example, workSheet.CreateFreezePane(5, 2, 6, 7) will have a freeze pane from columns(A-E) and rows(1-2) with 1 column and 5 row scroll. When the worksheet is first opened, it will show columns A-E, G-... and the rows will show 1-2, 8-...

If you have a large table of data in Excel, it can be useful to freeze rows or columns. This way you can keep rows or columns visible while scrolling through the rest of the worksheet.

You can download a project file from this link.

Navigate to the "Freeze Panes" How-To article for more information and demonstrations.

// Example of how to use CreateFreezePane method in C#
// Assume that 'workSheet' is a valid Excel worksheet object

// This will freeze the first column and the first four rows.
// Column A and rows 1-4 will remain visible while scrolling.
workSheet.CreateFreezePane(1, 4);

// This will freeze columns A-E and rows 1-2 and sets the scrollable area.
// When opened, the view will start from column F and row 8.
workSheet.CreateFreezePane(5, 2, 6, 7);

// Note: The first two parameters define the pane to freeze.
// The third and fourth parameters define the starting position of the scrollable area.
// Example of how to use CreateFreezePane method in C#
// Assume that 'workSheet' is a valid Excel worksheet object

// This will freeze the first column and the first four rows.
// Column A and rows 1-4 will remain visible while scrolling.
workSheet.CreateFreezePane(1, 4);

// This will freeze columns A-E and rows 1-2 and sets the scrollable area.
// When opened, the view will start from column F and row 8.
workSheet.CreateFreezePane(5, 2, 6, 7);

// Note: The first two parameters define the pane to freeze.
// The third and fourth parameters define the starting position of the scrollable area.
' Example of how to use CreateFreezePane method in C#
' Assume that 'workSheet' is a valid Excel worksheet object

' This will freeze the first column and the first four rows.
' Column A and rows 1-4 will remain visible while scrolling.
workSheet.CreateFreezePane(1, 4)

' This will freeze columns A-E and rows 1-2 and sets the scrollable area.
' When opened, the view will start from column F and row 8.
workSheet.CreateFreezePane(5, 2, 6, 7)

' Note: The first two parameters define the pane to freeze.
' The third and fourth parameters define the starting position of the scrollable area.
$vbLabelText   $csharpLabel