Skip to footer content
USING IRONXL

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling

When working with large Excel documents containing hundreds of rows, keeping your header row visible while scrolling through data can be a challenge. The VB .NET Excel freeze top row functionality solves this issue by locking specific rows and columns in place. This article demonstrates how to use IronXL to create freeze panes programmatically in your .NET applications, helping users navigate spreadsheet data with speed and ease.

Get started with a free trial to follow along with the code examples below.

How Can I Freeze Rows in an Excel File?

The answer is straightforward: use the CreateFreezePane method on your worksheet object. This method accepts parameters that control which rows and columns remain visible while the rest of the Excel sheet scrolls freely. When you freeze the first row, your header stays locked at the top no matter how far down you scroll through the data, similar to Excel's native Freeze Panes feature.

The following code snippet shows how to load an existing Excel document and freeze the top row:

Imports IronXL
Imports System.Linq
Module Program
    Sub Main()
        ' Load an existing workbook from file
        Dim workBook As WorkBook = WorkBook.Load("financial_report.xlsx")
        Dim workSheet As WorkSheet = workBook.WorkSheets.First()
        ' Freeze the first row to keep headers visible
        workSheet.CreateFreezePane(0, 1)
        ' Save the Excel file with freeze panes applied
        workBook.SaveAs("financial_report_Frozen.xlsx")
    End Sub
End Module
Imports IronXL
Imports System.Linq
Module Program
    Sub Main()
        ' Load an existing workbook from file
        Dim workBook As WorkBook = WorkBook.Load("financial_report.xlsx")
        Dim workSheet As WorkSheet = workBook.WorkSheets.First()
        ' Freeze the first row to keep headers visible
        workSheet.CreateFreezePane(0, 1)
        ' Save the Excel file with freeze panes applied
        workBook.SaveAs("financial_report_Frozen.xlsx")
    End Sub
End Module
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 1 - Excel file with frozen first row

The CreateFreezePane(0, 1) method call freezes zero columns and one row. This keeps the top row visible while allowing all columns to scroll left and right. The parameters set which rows and columns exist above and to the left of the scrolling area. Thanks to this simple approach, users can check their data against header labels without losing their place in large documents.

What Are the Steps to Freeze the First Column?

To freeze the first column instead of rows, simply adjust the parameters in the CreateFreezePane method. This is helpful when your Excel spreadsheet contains identifier information in column A that you want to keep visible while scrolling through additional columns to the right.

The following code snippet demonstrates how to create a new workbook and freeze the first column:

Imports IronXL
Module Program
    Sub Main()
        ' Create a new workbook and worksheet
        Dim workBook As WorkBook = WorkBook.Create()
        Dim workSheet As WorkSheet = workBook.CreateWorkSheet("SalesData")
        ' Add sample header and data to the range
        workSheet("A1").Value = "Product ID"
        workSheet("B1").Value = "Q1 Sales"
        workSheet("C1").Value = "Q2 Sales"
        ' Freeze the first column to keep Product IDs visible
        workSheet.CreateFreezePane(1, 0)
        ' Save as xlsx file
        workBook.SaveAs("SalesReport.xlsx")
    End Sub
End Module
Imports IronXL
Module Program
    Sub Main()
        ' Create a new workbook and worksheet
        Dim workBook As WorkBook = WorkBook.Create()
        Dim workSheet As WorkSheet = workBook.CreateWorkSheet("SalesData")
        ' Add sample header and data to the range
        workSheet("A1").Value = "Product ID"
        workSheet("B1").Value = "Q1 Sales"
        workSheet("C1").Value = "Q2 Sales"
        ' Freeze the first column to keep Product IDs visible
        workSheet.CreateFreezePane(1, 0)
        ' Save as xlsx file
        workBook.SaveAs("SalesReport.xlsx")
    End Sub
End Module
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 2 - Excel file with frozen first column

Here, CreateFreezePane(1, 0) freezes one column and zero rows. The first column remains locked on the left side of the page while users scroll horizontally to read additional cell data. This is particularly true for financial reports or inventory lists where product codes must stay visible.

How Do I Freeze Both Rows and Columns Together?

For desktop applications handling complex Excel documents, you may need to freeze panes that lock both the top row and the first column simultaneously. This keeps your header labels and row identifiers visible no matter which direction you scroll, making it easier to understand and filter through your cell data.

Imports IronXL
Module Program
    Sub Main()
        ' Load workbook or create new one
        Dim workBook As WorkBook = WorkBook.Load("Inventory.xls")
        Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
        ' Freeze first row AND first column
        workSheet.CreateFreezePane(1, 1)
        ' Save the document
        workBook.SaveAs("Inventory_Frozen.xlsx")
    End Sub
End Module
Imports IronXL
Module Program
    Sub Main()
        ' Load workbook or create new one
        Dim workBook As WorkBook = WorkBook.Load("Inventory.xls")
        Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
        ' Freeze first row AND first column
        workSheet.CreateFreezePane(1, 1)
        ' Save the document
        workBook.SaveAs("Inventory_Frozen.xlsx")
    End Sub
End Module
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 3 - Output Excel file with the first row and column frozen

The CreateFreezePane(1, 1) call sets the freeze panes to lock one column and one row. When you open this file in Excel, scrolling in any direction keeps the header row and ID column visible on the page. This answers a common question developers have when building reporting applications.

What Is the Advanced Freeze Panes Method with Pre-Scrolling?

IronXL provides an advanced option using four parameters that lets you add freeze panes with a pre-scrolled starting position. This controls not only what rows and columns are frozen but also where the scrolling area begins when users first open the file.

Imports IronXL
Module Program
    Sub Main()
        Dim workBook As WorkBook = WorkBook.Load("LargeDataset.xlsx")
        Dim workSheet As WorkSheet = workBook.WorkSheets.First()
        ' Freeze columns A-B and rows 1-3, with pre-scroll to show row 8
        workSheet.CreateFreezePane(2, 3, 2, 7)
        workBook.SaveAs("LargeDataset_Configured.xlsx")
    End Sub
End Module
Imports IronXL
Module Program
    Sub Main()
        Dim workBook As WorkBook = WorkBook.Load("LargeDataset.xlsx")
        Dim workSheet As WorkSheet = workBook.WorkSheets.First()
        ' Freeze columns A-B and rows 1-3, with pre-scroll to show row 8
        workSheet.CreateFreezePane(2, 3, 2, 7)
        workBook.SaveAs("LargeDataset_Configured.xlsx")
    End Sub
End Module
$vbLabelText   $csharpLabel

Output

VB .NET Excel Freeze Top Row: Keep Headers Visible While Scrolling: Image 4 - Advanced output Excel file

The additional parameters select where the split view starts. In this example, when the workbook opens, rows 1-3 remain frozen at the end of the visible area while the scrolling section begins at row 8. Mind that only one freeze pane configuration can exist per worksheet, any subsequent call will overwrite the previous setting.

How Do I Remove Freeze Panes from a Worksheet?

If freeze panes already exist and you need to remove them, the RemovePane method handles this action. This is helpful when you need to install a different freeze configuration or return the sheet to normal scrolling.

' Remove all existing freeze or split panes
workSheet.RemovePane()
' Remove all existing freeze or split panes
workSheet.RemovePane()
$vbLabelText   $csharpLabel

This single line clears any freeze panes that exist on the worksheet, allowing you to create fresh formatting or leave the document without frozen sections.

Note that freeze panes do not work with Microsoft Excel 97-2003 (.xls) format due to file format limitations. For best results, save your documents as .xlsx files. If you run into any issue with downloaded files not displaying freeze panes correctly, check that you're using a compatible Excel version.

Conclusion: Master Spreadsheet Navigation with IronXL

Implementing freeze panes is one of the most effective ways to improve the user experience of your .NET Excel reports. By locking headers and identifiers in place, you transform static data into an interactive reporting tool that users can navigate with confidence.

Throughout this guide, we have seen how IronXL simplifies complex spreadsheet tasks:

  • Simplicity: Use CreateFreezePane with just two parameters for standard row or column locking.
  • Precision: Utilize advanced four-parameter overloads to set custom scrolling starting points, ideal for tracking performance in large spreadsheets.
  • Flexibility: Easily remove or update panes as your data requirements change.

Beyond just freezing rows, IronXL provides a comprehensive suite of tools for server side Excel manipulation. Whether you need to format cells, apply conditional formatting rules, or generate pivot charts, the library handles these operations efficiently without the need for Microsoft Office. Its cross platform compatibility ensures that your VB.NET code runs seamlessly across Windows, Linux, and macOS environments.

Learn more about working with worksheets and explore additional cell range operations in the IronXL documentation. The library also supports adding rows and columns and creating Excel charts for comprehensive spreadsheet automation.

I hope this post has been helpful in showing how to implement freeze panes in your VB.NET application. For production use, purchase a license to unlock all features and deploy with confidence.

Get stated with IronXL now.
green arrow pointer

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More