How to lock specified cells without protecting the whole worksheet in Excel?
Normally, you need to protect the whole worksheet for locking cells from editing. Is there any method to lock cells without protecting the whole worksheet? This article recommend a VBA method for you.
Lock specified cells without protecting the whole worksheet with VBA
Lock specified cells without protecting the whole worksheet with VBA
Supposing you need to lock cell A3 and A5 in current worksheet, the following VBA code will help you achieve it without protecting the whole worksheet.
1. Right click the sheet tab, and select View Code from the right-clicking menu.
2. Then copy and paste the below VBA code into the Code window. See screenshot:
VBA code: Lock specified cells without protecting the whole worksheet
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then
If Target.Row = 3 Or Target.Row = 5 Then
Beep
Cells(Target.Row, Target.Column).Offset(0, 1).Select
End If
End If
End Sub
Note: In the code, Column 1, Row = 3 and Row = 5 indicate cell A3 and A5 in current worksheet will be locked after running the code. You can change them as you need.
3. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.
Now cell A3 and A5 are locked in current worksheet. If you try to select cell A3 or A5 in current worksheet, the cursor will be moved to the right adjacent cell automatically.
Related articles:
- How to lock all cell references in formulas at once in Excel?
- How to lock or protect cells after data entry or input in Excel?
- How to lock or unlock cells based on values in another cell in Excel?
- How to lock picture/image to or inside cell in Excel?
- How to lock cell width and height from resizing in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!



















