How to Lock a Row in Excel: Everything You Need to Know
Written by the team at Iron Software
If your header row keeps disappearing as you scroll down a spreadsheet, or if colleagues keep accidentally overwriting key data, you need to lock that row. Excel gives you two distinct ways to do this, freezing a row so it stays visible while you scroll, and protecting a row so the contents stay safe from edits. This guide will assist users with step-by-step instructions for getting started with locking rows in Excel. These methods work in any Excel spreadsheet, which is part of the Microsoft Office suite.
To keep an area of a worksheet visible while scrolling, go to the View tab and select Freeze Panes.
Let’s start with the fastest approach. *
The Quickest Way: Freeze the Top Row in One Click
For the case where you simply want your header row to stay visible while scrolling, this is the fastest path. The Freeze Top Row option will lock the first row of your worksheet.
- Open your spreadsheet in Excel.
-
Click the View tab in the ribbon at the top.
-
Click the Freeze Panes button in the Window group.
- Select Freeze Top Row from the dropdown to lock the first row.
That’s it. A thin grey line will appear beneath row 1, indicating the first row is now locked in place. Scroll down as far as you like, the header stays put.
To lock a row in Excel, go to the View tab and click Freeze Panes.

Method 1: Freeze Any Row Using the Ribbon (Freeze Panes)
"Freeze Top Row" applies to row 1. If you want to lock row 3, row 5, or any other row, use Freeze Panes instead. To freeze multiple rows or columns, select the cell below the last row and to the right of the last column you want to keep visible, then click Freeze Panes.
How to do it:
-
Click on the row below the one you want to freeze. For example, to lock rows 1–3, click anywhere in row 4. If you want to freeze both rows as well as columns, select the cell below the last row and to the right of the last column you want frozen. For example, to freeze the first two columns, select the third column, or to freeze the first column, select the cell in column B.
-
Go to the View tab.
- Click Freeze Panes.
- Select Freeze Panes (the first option in the dropdown, not “Freeze Top Row”).
Freezing columns works the same way: to freeze the first column, select column B; to freeze multiple columns, select the column to the right of the last column you want frozen, and then click Freeze Panes. You can also freeze the last row or last column by selecting the appropriate cell, which keeps the rest of your data visible while scrolling.
Many users find it difficult to figure out which cell to select when freezing both rows and columns. It's important to ensure you select the correct cell below and to the right of the area you want to keep visible before applying Freeze Panes. This will help avoid issues and make sure the Freeze Panes feature is applied correctly.
Excel will freeze every row above your selected row and every column to the left of your selected column. The grey dividing line will appear just above and to the left of where you clicked.
To unfreeze: Go to View → Freeze Panes → Unfreeze Panes. The option only appears if panes are currently frozen.

Method 2: Freeze a Row Using a Keyboard Shortcut
Excel uses Alt key sequences to reach Freeze Panes, letting you navigate there entirely from the keyboard. For users looking for a quick answer, the following keyboard sequence provides an efficient way to lock rows in Excel:
To freeze the top row:
Press Alt → W → F → R (one key at a time, not simultaneously).
- Alt activates the ribbon key tips.
- W opens the View tab.
- F opens the Freeze Panes menu.
- R selects “Freeze Top Row.”
These steps are designed with careful thought to guide users through the process efficiently.
To freeze a specific row:
First, select the row below the one you want to freeze using the keyboard (use arrow keys or Ctrl + G to go to a cell), then press Alt → W → F → F.
To unfreeze:
Press Alt → W → F → F again. When panes are frozen, this option toggles to “Unfreeze Panes.”
Method 3: Lock a Row from Being Edited (Protect Sheet)
Freezing keeps a row visible, it doesn’t stop anyone from editing it. If you want to prevent changes to specific rows, you need Excel’s sheet protection feature. The following information is based on expert guidance for protecting rows in Excel. This is a two-step process.
Step 1: Unlock All Cells First
By default, every cell in Excel is marked as "locked," but this setting only takes effect when sheet protection is turned on. To lock only certain rows, you first need to unlock everything, then re-lock just the rows you care about.
-
Press Ctrl + A to select all cells.
-
Press Ctrl + 1 to open the Format Cells dialog (or right-click and choose Format Cells).
-
Click the Protection tab.
-
Uncheck the "Locked" checkbox.
- Click OK.

Step 2: Lock Only the Rows You Want to Protect
-
Select the row(s) you want to lock. Click the row number on the left to select the entire row. Hold Ctrl and click additional row numbers to select multiple rows.
-
Press Ctrl + 1 again to open Format Cells.
-
Go to the Protection tab.
-
Check the "Locked" checkbox.
- Click OK.
Step 3: Turn On Sheet Protection
-
Go to the Review tab in the ribbon.
- Click Protect Sheet.
- In the dialog that appears, choose what users can still do (e.g., select cells, sort, use AutoFilter).
- Optionally, enter a password to prevent others from removing the protection.
- Click OK.
Now, anyone who tries to edit the locked rows will see a pop-up saying the cell is protected.

To unprotect: Go to Review → Unprotect Sheet, enter the password if one was set. *
Method 4: Lock a Row via the Right-Click Context Menu
You can reach the same Format Cells protection settings without touching the ribbon at all.
- Select the row or rows you want to lock (click the row number).
-
Right-click on the selection.
-
Choose Format Cells from the context menu.
-
Click the Protection tab.
-
Check or uncheck Locked as needed.
- Click OK, then protect the sheet via Review → Protect Sheet.
This method is handy if you’re already working with right-click menus and don’t want to navigate the ribbon.
Method 5: Lock a Row Using a VBA Macro
If you lock rows repeatedly or want to automate this across multiple files, a VBA macro saves time. This method is for intermediate users comfortable opening the Visual Basic editor.
To open the VBA editor: Press Alt + F11.
To freeze the top row programmatically:
Sub FreezeTopRow()
With ActiveWindow
.FreezePanes = False ' Clear any existing freeze first
ActiveSheet.Cells(2, 1).Select
.FreezePanes = True
End With
End Sub
Sub FreezeTopRow()
With ActiveWindow
.FreezePanes = False ' Clear any existing freeze first
ActiveSheet.Cells(2, 1).Select
.FreezePanes = True
End With
End Sub
Sub FreezeTopRow()
With ActiveWindow
.FreezePanes = False ' Clear any existing freeze first
ActiveSheet.Cells(2, 1).Select()
.FreezePanes = True
End With
End Sub
To lock a row from editing and protect the sheet:
Sub LockRowAndProtect()
Dim ws As Worksheet
Set ws = ActiveSheet
' Step 1: Unlock all cells
ws.Cells.Locked = False
' Step 2: Lock row 1
ws.Rows(1).Locked = True
' Step 3: Protect the sheet (no password in this example)
ws.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub LockRowAndProtect()
Dim ws As Worksheet
Set ws = ActiveSheet
' Step 1: Unlock all cells
ws.Cells.Locked = False
' Step 2: Lock row 1
ws.Rows(1).Locked = True
' Step 3: Protect the sheet (no password in this example)
ws.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Option Strict On
Sub LockRowAndProtect()
Dim ws As Worksheet
ws = ActiveSheet
' Step 1: Unlock all cells
ws.Cells.Locked = False
' Step 2: Lock row 1
ws.Rows(1).Locked = True
' Step 3: Protect the sheet (no password in this example)
ws.Protect(Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True)
End Sub
To run the macro: Press Alt + F8, select your macro name, and click Run. *
Method 6: Freeze Rows and Columns at the Same Time
You can create a customized view in Excel by freezing both rows and columns simultaneously, useful for large datasets where you need both the header row and a label column to stay visible. A common question is how to lock both rows and columns at the same time. To do this, click on the View tab and select Freeze Panes to lock specific rows and columns in place.
-
Click the cell that sits at the intersection of the row and column you want to freeze. For example, to freeze row 1 and column A, click cell B2.
- Go to View → Freeze Panes → Freeze Panes.
Both everything above row 2 and everything left of column B will now be locked in place while scrolling.
Common Issues and Troubleshooting
"Freeze Panes" is greyed out
This usually happens when your spreadsheet is in Page Layout view or Page Break Preview. Click View → Normal to switch back to normal view, then try again.
The freeze line appears in the wrong place
You may have a cell selected in the middle of a range rather than at the edge. Click the exact row below where you want the freeze line, then apply Freeze Panes.
The row is visible but users can still edit it
Freezing only affects visibility, not editability. To block edits, you need to follow the Protect Sheet steps in Method 3 above.
Protection is on but users can still edit locked rows
Double-check that you completed Step 1 (unlocking all cells) before re-locking just your target rows. If all cells are locked before protection, the setting defaults to protecting everything which sounds right but often causes confusion when you later try to allow editing in specific areas.
Forgot the sheet protection password
Excel doesn't have a built-in recovery tool for sheet passwords. Third-party tools exist that can remove protection, or for older .XLS files, the protection can sometimes be worked around by copying the sheet's content into a new workbook.
Freeze Panes disappear when sending the file to someone
Freeze pane settings are saved with the file in .XLSX format. If the recipient sees no freeze, they may have toggled it off accidentally, or opened the file in a viewer that doesn't support panes. Ask them to check View → Freeze Panes.
Lock a row in Excel Online (browser version)
If you're just getting started with Excel for the web, you can use Freeze Panes to lock a row. Excel for the web supports Freeze Panes, click View → Freeze Rows & Columns, then choose your preferred option. Sheet protection is also available under Review → Protect Sheet, though some advanced protection options are only available in the desktop app.
Bonus Tip: Split Panes vs. Freeze Panes
A feature often confused with Freeze Panes is Split. Found under View → Split, this divides your Excel window into separate scrollable sections, you can view two different parts of the same sheet at once. Unlike Freeze Panes, Split doesn't lock a row in a fixed position; it just splits the view. If you accidentally applied a split instead of a freeze, go to View → Split again to toggle it off. *
For Developers: How to Lock Rows Programmatically with IronXL
If you're building software that generates or processes Excel files, manually configuring freeze panes and protection through the UI doesn't scale. IronXL is a .NET library that lets you apply row locking, sheet protection, and freeze panes directly in C# or VB.NET, no Excel installation required.
Here's how to freeze the top row and protect it from edits in a few lines of code:
using IronXL;
WorkBook workBook = WorkBook.Load("report.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Freeze the top row
workSheet.CreateFreezePane(0, 1);
// Lock all cells, then unlock the editable range
workSheet.GetRange("A1:Z1").Style.Locked = true;
workBook.Password = "securePassword";
workBook.SaveAs("report-locked.xlsx");
using IronXL;
WorkBook workBook = WorkBook.Load("report.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Freeze the top row
workSheet.CreateFreezePane(0, 1);
// Lock all cells, then unlock the editable range
workSheet.GetRange("A1:Z1").Style.Locked = true;
workBook.Password = "securePassword";
workBook.SaveAs("report-locked.xlsx");
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("report.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
' Freeze the top row
workSheet.CreateFreezePane(0, 1)
' Lock all cells, then unlock the editable range
workSheet.GetRange("A1:Z1").Style.Locked = True
workBook.Password = "securePassword"
workBook.SaveAs("report-locked.xlsx")
IronXL handles the complexity of the OpenXML format so you don't have to. It's particularly useful for teams generating reports, exports, or templates at scale where row locking needs to be applied consistently across hundreds of files. *
Summary: Which Method Should You Use?
| Goal | Best Method | | --- | --- | | Keep header row visible while scrolling | View → Freeze Top Row | | Keep multiple rows visible while scrolling | Click row below, then Freeze Panes | | Prevent anyone from editing a row | Format Cells → Lock + Protect Sheet | | Work without touching the ribbon | Right-click → Format Cells | | Automate across multiple files | VBA Macro | | Programmatic file generation | IronXL (.NET) |
Locking a row in Excel comes down to two questions: do you want it to stay visible, or do you want it to stay unchanged? Freezing specific rows or columns keeps them visible while the rest of the data scrolls, making it easier to work with large spreadsheets. Freezing headers keeps headings visible while scrolling, which enhances data analysis and improves data entry accuracy. Freeze Panes answers the first; Protect Sheet answers the second. Used together, they give you full control over how your spreadsheet behaves for you and anyone you share it with.




