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.
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,904
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Tanner_2004

Well-known Member
Joined
Jun 1, 2010
Messages
616
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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,904
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Thank you, I will give it a try. I appreciate your help. Where would i deposit this code? Please.

Place in a standard module
Alt+F11 then from menu Insert > Module
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,904
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
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
 

madsm92

New Member
Joined
Apr 25, 2012
Messages
8
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,114
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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
 

Forum statistics

Threads
1,186,126
Messages
5,956,045
Members
438,231
Latest member
fuzdrum

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
Top