Lesson 28 of 92 · Free Excel Course
Excel
Locking Formulas in Excel: Protect Cells, Sheets and Workbooks
Lock only the formula cells in Excel so people can still type inputs, hide formulas, protect sheets and workbooks, and know what protection can't do.
You've built a sheet that works. The totals add up, the differences are right, and then someone types a number straight over a formula and nobody notices for a month. Locking formulas stops that. In this lesson you'll lock only the formula cells so people can still type their inputs, hide formulas if you want, protect whole workbooks, and learn what Excel's protection can and can't do. At the end there's a short section on the other two things people mean by "lock" in Excel: dollar signs in formulas and frozen headings.
The key idea: Locked does nothing until you protect the sheet
Locking in Excel is two switches, and both have to be on.
- The Locked setting on each cell. It lives in Format Cells, on the Protection tab. Here's the surprise: every cell in a new workbook is already ticked as Locked.
- Sheet protection. Nothing is actually guarded until you click Review, then Protect Sheet.
So if you protect a sheet straight away, every cell becomes read-only, including the ones people are supposed to type in. The trick is to untick Locked on the input cells first, then protect. Formulas on a protected sheet still recalculate normally; protection only blocks typing, deleting and (unless you allow them) formatting.
Here's the budget used through this lesson. The shaded cells are inputs: what people should be allowed to change. Everything in column D, row 7 and B10 is a formula.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Budget | Actual | Difference |
| 2 | Rent | $1,200 | $1,200 | $0 |
| 3 | Groceries | $400 | $435 | $35 |
| 4 | Transport | $150 | $120 | -$30 |
| 5 | Utilities | $180 | $195 | $15 |
| 6 | Fun | $100 | $95 | -$5 |
| 7 | Total | $2,030 | $2,045 | $15 |
| 8 | ||||
| 9 | Income | $2,500 | ||
| 10 | Left over | $455 |
Lock only the formula cells
This is the method most people want: formulas locked, everything else open. It works on any sheet, however many formulas it has.
- Unlock everything. Click the Select All triangle at the top-left corner of the grid (or press Ctrl+A until the whole sheet is selected). Press Ctrl+1 to open Format Cells, go to the Protection tab, untick Locked, and click OK.
- Select just the formulas. Press Ctrl+G (or F5) to open Go To, click Special, choose Formulas, and click OK. You can also get there from Home, Find & Select, Go To Special. Excel selects every formula cell on the sheet at once.
- Lock them. With the formulas still selected, press Ctrl+1, tick Locked on the Protection tab (tick Hidden too if you want to hide them; see below), and click OK.
- Protect the sheet. Click Review, then Protect Sheet. Leave the protection box at the top ticked, type a password if you want one, pick what people may still do (next section), and click OK. Confirm the password if asked.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Budget | Actual | Difference |
| 2 | Rent | $1,200 | $1,200 | $0 |
| 3 | Groceries | $400 | $435 | $35 |
| 4 | Transport | $150 | $120 | -$30 |
| 5 | Utilities | $180 | $195 | $15 |
| 6 | Fun | $100 | $95 | -$5 |
| 7 | Total | $2,030 | $2,045 | $15 |
| 8 | ||||
| 9 | Income | $2,500 | ||
| 10 | Left over | $455 |
Now try typing over D3. Excel shows a message saying the cell is on a protected sheet. Type a new figure in C3 instead and it's accepted, and the difference and totals update straight away.
If your sheet is small, you can skip Go To Special: select the input cells by hand (hold Ctrl to pick separate areas), untick Locked for just those, then protect. The result is the same.
Choose what people can still do
The Protect Sheet dialog has a list headed Allow all users of this worksheet to. By default only Select locked cells and Select unlocked cells are ticked. The useful ones:
- Select locked cells. Untick it and people can't even click on your formulas. Combined with Select unlocked cells, pressing Tab then jumps only between input cells, which makes a neat form.
- Format cells, Format columns, Format rows. Let people change colours, widths and heights.
- Insert rows, Delete rows (and columns). Tick these if people need to add lines to a list.
- Sort and Use AutoFilter. Microsoft notes two catches: people can't sort a range that contains locked cells, and they can't turn filter buttons on or off. Switch filters on before you protect.
You can come back and change these: unprotect, then protect again with different ticks.
Hide formulas from the formula bar
Locked stops changes, but anyone can still click D3 and read =C3-B3 in the formula bar. If you'd rather they didn't:
- Select the formula cells (Go To Special, Formulas, as above).
- Press Ctrl+1, go to Protection, tick Hidden, and click OK.
- Protect the sheet.
The cells still show their results, but the formula bar stays empty when they're selected. Like Locked, Hidden does nothing until the sheet is protected. To see formulas again, unprotect the sheet; untick Hidden if you want them visible next time you protect.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Budget | Actual | Difference |
| 2 | Rent | $1,200 | $1,200 | $0 |
| 3 | Groceries | $400 | $435 | $35 |
| 4 | Transport | $150 | $120 | -$30 |
Passwords, and what protection is not
A password is optional. Without one, anyone can click Review, Unprotect Sheet and carry on, which is fine if you only want to prevent accidents. With one, they need the password.
Two warnings, both straight from Microsoft:
- Lost passwords can't be recovered. Microsoft can't retrieve a forgotten sheet or workbook password. Write it down somewhere safe, or keep an unprotected master copy.
- Sheet protection is not security. Microsoft says worksheet protection "isn't intended as a security feature." It stops people editing cells by mistake. It doesn't encrypt anything, and people can still copy the values elsewhere. Don't use it to hide salaries or anything private.
On a Mac, passwords are limited to 15 characters, and Microsoft warns that a file protected on Windows with a longer password can't be opened on a Mac.
Protect Workbook, Encrypt with Password and Mark as Final
Excel has several "protect" buttons that sound alike but do different jobs:
| Feature | Where | What it stops |
|---|---|---|
| Protect Sheet | Review tab | Editing locked cells on one sheet |
| Protect Workbook | Review tab | Adding, deleting, renaming, moving, hiding or unhiding sheets |
| Encrypt with Password | File, Info, Protect Workbook | Opening the file at all without the password |
| Mark as Final | File, Info, Protect Workbook | Nothing really: it's a polite "please don't edit" |
Protect Workbook protects the structure. People can still edit cells (unless the sheets are protected too), but they can't add, delete or rename sheets. Click Review, Protect Workbook, add an optional password, and click OK.
Encrypt with Password is the real lock. Click File, Info, Protect Workbook, Encrypt with Password, type a password twice, and save. Anyone opening the file now needs it, and again, Microsoft can't recover it.
Mark as Final makes the file open read-only with a message bar. Microsoft is clear that it isn't a security feature: anyone can click Edit Anyway.
Allow Edit Ranges (Review tab, Windows only) lets you give different ranges their own passwords, so one person can edit January and another February. It's only available while the sheet is unprotected. Most people won't need it.
Unprotect a sheet
Click Review, then Unprotect Sheet (the Protect Sheet button changes name when protection is on), and type the password if there is one. On Windows, File, Info, Protect, Unprotect Sheet also works.
Mac and Excel for the web
Mac: the steps match Windows. Open Format Cells with Cmd+1 (or Format, Cells), use the Protection tab for Locked and Hidden, then Review, Protect Sheet. Ctrl+G opens Go To.
Excel for the web works differently: there's no Locked checkbox to set first. Click Review, then Manage Protection. Add your input cells under Unlocked ranges (each can have its own optional password), turn on Protect sheet, set a Sheet protection password if you like, and pick what's allowed under Options. The sheet tab shows a lock icon. You can also Pause Protection to make a quick change, then Resume Protection. Workbook passwords (Encrypt with Password) can't be added in the browser; Microsoft says to use Open in Excel for that.
The other "lock": dollar signs and frozen headings
Searching "lock formula" or "lock a cell" often means one of two other things:
- Locking a cell reference so it doesn't move when you copy a formula. That's an absolute reference:
=C2*$G$1keeps pointing at G1 on every row. Press F4 while editing to add the dollar signs. It's covered fully in Absolute and relative references. - Keeping headings on screen while you scroll. That's View, Freeze Panes, covered in Rows and columns.
Neither one protects anything from being edited.
Try it yourself
Download the practice workbook. Protection can't be built into the file in advance, so the Your task sheet walks you through it on the Practice budget.
- Select the whole sheet and untick Locked in Format Cells.
- Use Go To Special, Formulas, to select the eight formula cells. Tick Locked and Hidden.
- Protect the sheet with the password
budgetand untick Select locked cells. - Type a new Actual figure in C3. The difference and totals should update.
- Try to type in D3. Excel should refuse.
- Press Tab a few times and notice it skips the formulas.
- Unprotect the sheet, then protect the workbook structure and try renaming a sheet.
Compare your results with the Answer key sheet, which lists every cell that should be locked, unlocked or hidden.
Common mistakes
- Locking without protecting. Ticking Locked alone changes nothing. You must click Protect Sheet.
- Protecting without unlocking inputs. The whole sheet goes read-only, including cells people need to type in.
- Forgetting the password. It can't be recovered. Store it safely before you share the file.
- Treating protection as security. Use Encrypt with Password for private data, not Protect Sheet.
- Expecting sort and filter to work. Tick Sort and Use AutoFilter when you protect, and turn filters on first.
- Confusing the three locks. Protect Sheet guards cells, $ signs fix references, Freeze Panes keeps headings visible.
What's next
Your formulas are now safe from accidental typing. Back in Printing you set up your sheet for paper; next, Keyboard shortcuts shows the keys that make all of this faster, including Ctrl+1 and Ctrl+G. Or go back to the full Excel course.
Frequently asked questions
Can I lock cells in Excel without protecting the sheet?
No. Every cell is already marked Locked, but that setting does nothing until you turn on Review > Protect Sheet. Locking just tells Excel which cells to guard once protection is switched on.
How do I lock formulas but still let people type in other cells?
Unlock the input cells first: select them, press Ctrl+1 (Cmd+1 on a Mac), open the Protection tab and untick Locked. Leave the formula cells locked, then click Review > Protect Sheet. People can type in the unlocked cells, and the formulas keep recalculating.
How do I lock a cell reference in a formula so it doesn't change when I copy it?
That's a different kind of lock: an absolute reference. Click in the reference while editing the formula and press F4 (Cmd+T on a Mac) to turn A1 into $A$1. See Absolute and relative references.
What if I forget the password for a protected sheet?
Microsoft can't retrieve it for you. Keep a copy of the password somewhere safe, or keep an unprotected master copy of the file. Without the password you'd have to rebuild the protected parts.
Why can't I sort or filter a protected sheet?
Sorting and filtering are off unless you allow them. When you protect the sheet, tick Sort and Use AutoFilter. Even then, Microsoft notes that people can't sort a range containing locked cells, and filter buttons must already be on before you protect.
Is a protected Excel sheet secure?
No. Microsoft says worksheet protection isn't intended as a security feature; it stops accidental edits. To stop people opening the file at all, use File > Info > Protect Workbook > Encrypt with Password.