Can you lock one cell without protecting the whole sheet?

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
Is there a way to protect cells containing formulas without protecting the whole sheet?

I'm sick of people messing up the spreadsheet by overwriting the formulas, but they need to be able to save their work.

Thanks.
 
not sure what happened with last post but will,
try again without tags.

Sub ProtectFormulas()

With ActiveSheet
.Unprotect Password:="" '<<add password if required
.Cells.Locked = False
.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect Password:=""

'allow selection of unlocked cells only
.EnableSelection = xlUnlockedCells
End With

End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Thank you, I will give it a try. I appreciate your help. Where would i deposit this code? Please.

not sure what happened with last post but will,
try again without tags.

Sub ProtectFormulas()

With ActiveSheet
.Unprotect Password:="" '<<ADD if password required
.Cells.Locked = False
.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect Password:=""

'allow selection of unlocked cells only
.EnableSelection = xlUnlockedCells
End With

End Sub
 
Upvote 0
just noticed code still did not show correctly when I pasted 2nd time. Hopefully, 3rd time lucky!

dave

Sub ProtectFormulas()

With ActiveSheet
.Unprotect Password:="" '<<ADD required
add password if required
.Cells.Locked = False
.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect Password:=""

'allow selection of unlocked cells only
.EnableSelection = xlUnlockedCells
End With

End Sub
 
Upvote 0
Oh wow, this is an old thread!

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address <> "$U$14" Then Exit Sub
Application.EnableEvents = False
MsgBox "Hey, leave me alone!", 48, "Sorry, I'm protected."
Application.Undo
Application.EnableEvents = True
End Sub

This one worked great for me. How would I go about if I were to lock several cells? I want to lock cells X15:Z22.
Any help is much appreciated.
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)    
If Intersect(Target, Range("X15:Z22")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    MsgBox "Hey, leave me alone!", 48, "Sorry, I'm protected."
    Application.Undo
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top