In Excel: paste Sub UnprotectSheet() into the VBA editor (Alt + F11 → Insert ▸ Module), press F5 to run, and save as .xlsm to keep the macro.
VBA macro: Unprotect Sheet with VBA
Sub UnprotectSheet()
Dim ws As Worksheet
Set ws = ActiveSheet
On Error Resume Next
ws.Unprotect Password:="MyPassword123"
If ws.ProtectContents Then
MsgBox "Wrong password — sheet remains protected.", vbCritical
Else
MsgBox "Sheet unprotected.", vbInformation
End If
On Error GoTo 0
End SubOn Error Resume Next suppresses the runtime error when the password is wrong; the If check afterward lets you show a user-friendly message instead.
How to run this macro
- Press Alt + F11 to open the VBA editor.
- Insert > Module.
- Paste the code above.
- Press
F5, or close the editor and run it from Developer > Macros. - Save the file as .xlsm so the macro is kept.
Open Excel and navigate to Developer ▸ Visual Basic (or press Alt + F11).
Select Insert ▸ Module from the menu bar inside the VBA editor.
Copy and paste Sub UnprotectSheet() into the Module.
Click anywhere inside the Sub body and press F5 to run.
Close the VBA editor and save the file as .xlsm.
What this does
Sub UnprotectSheet() is a ready-to-run VBA macro that handles unprotect a worksheet using a VBA macro without manual effort. VBA (Visual Basic for Applications) is Excel's built-in automation language: it can read every cell, loop through thousands of rows, and make decisions in milliseconds. To use it, open the VBA editor with Alt + F11, create a Module, paste the code, and press F5. The Unprotect Sheet with VBA macro will run immediately — no add-ins, no external tools, just Excel doing exactly what the code tells it to do. Keep the inputs visible and clearly labelled and the whole thing stays auditable — anyone who opens the file later, including you, can see at a glance exactly what feeds the result and change one assumption without hunting through the formula. Treat “excel vba unprotect sheet” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected sheet shows up while it is still harmless. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That turns a workspace setting that makes a big sheet comfortable to navigate into a method you can reuse, explain, and defend when the workbook leaves your screen.
A worked example
Example: a colleague sends you a large dataset and asks you to unprotect a worksheet using a VBA macro before handing it back. Open the VBA editor with Alt + F11, create a new Module, paste the Sub UnprotectSheet() code, and click Run (or press F5). Excel calls the Sub, runs through the sheet, and finishes the Unprotect Sheet with VBA task automatically. The whole operation takes seconds regardless of how many rows are involved — and because the macro is deterministic, it will produce the same result every time you run it on the same input. Reach for the Unprotect Sheet with VBA macro whenever unprotect a worksheet using a VBA macro is a task you repeat more than once, involves more than a handful of rows, or needs to be done consistently across multiple workbooks. VBA runs in milliseconds over data that would take minutes by hand, and it never makes the selection mistakes that manual workflows introduce when fatigue sets in. If there is any chance you will reuse this, drop it into a small template tab right now: a labelled input area on the left and the formula beside it, checked once against the tool above. Next time the same question comes up, the answer is a single paste away instead of a rebuild from memory.
In Google Sheets
If you are in Google Sheets rather than Excel, the good news is that the formula shown here is identical and the workflow barely changes — menus sit across the top instead of in a ribbon, and a few function names differ slightly, but anything you build here moves across with little or no rework. Nothing on this page is behind a login: the tool runs entirely in your browser, the formula is shown in full with one-click copy, and the steps work the same on Windows and Mac. That is the whole promise here — the exact answer, a way to prove it on your own numbers, and just enough context to make it stick. If you take one thing from this page on “excel vba unprotect sheet”, make it the habit rather than the keystrokes: set the problem up with labelled inputs, reference those cells, and let Excel do the recomputing. Bookmark the page for the syntax, but do the example once in a blank sheet and check it against the tool above — five minutes of hands-on practice fixes the method in memory far better than re-reading, and it surfaces the small snags while they are still harmless. After that the technique is genuinely yours: faster than searching for it again, and reliable enough to drop into work that other people depend on.
Common mistakes
- Missing Option Explicit at the top of the module — adding it forces VBA to flag typos in variable names immediately, saving time debugging.
- Not qualifying the range with the worksheet object — using Cells(1,1) without a ws. qualifier acts on whatever sheet is active; if the macro runs from a different sheet it may corrupt data. The pattern `Dim ws As Worksheet: Set ws = ActiveSheet` (or a specific sheet name) pins the action to the right place.
- Forgetting that macros cannot be undone with Ctrl+Z once they have modified the sheet. Test on a copy of the workbook before running on live data.
Frequently asked questions
How do I run the Unprotect Sheet with VBA macro?
Press Alt + F11 to open the VBA editor, insert a Module (Insert ▸ Module), paste Sub UnprotectSheet() into the code pane, and press F5. Alternatively close the editor and run it from Developer ▸ Macros ▸ select "UnprotectSheet" ▸ Run.
Why won't my macro run — macros are disabled?
Excel blocks macros by default for files downloaded from the internet. Click the yellow security bar and choose "Enable Content" — that trusts this one workbook and is all that is normally needed. Leave File ▸ Options ▸ Trust Center ▸ Trust Center Settings ▸ Macro Settings on "Disable VBA macros with notification" rather than switching to "Enable all macros", which Microsoft itself marks not recommended. If the bar is red instead of yellow, the file carries Mark of the Web: close Excel, right-click the file, open Properties and tick Unblock. Also ensure the file is saved as .xlsm, not .xlsx.
Can I undo what the Unprotect Sheet with VBA macro did?
No — VBA actions generally cannot be undone with Ctrl+Z because they bypass Excel's undo stack. Always test Sub UnprotectSheet() on a backup copy of the workbook before running it on live data, or add explicit validation logic inside the macro before the destructive step.