VBA code to unlock a cell if another cell's value is greater than 6.00

cor_dog2

New Member
Joined
Feb 28, 2013
Messages
5
Hello everyone,

I have a protected worksheet with most cells locked and some that are unlocked. I also know the password to unlock the sheet.
Does anyone know the VBA code to monitor a cell(B29 in my case) and if it has a value of 6.00 or more than it will unlock cell B34?

Seems simple enough, but can't quite get it to work. I am a noob, so maybe that is why. :)

Any help would be greatly appreciated!!
Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi VoG, it uses a formula to add other cells.
To be exact the formula is: =B12+B15+B18+B21+B24+B27
 
Upvote 0
Try this: right click the sheet tab, select View Code and paste in

Rich (BB code):
Private Sub Worksheet_Calculate()
If Range("B29").Value >= 6 Then
    Me.Unprotect Password:="pw"
    Range("B34").Locked = False
    Me.Protect Password:="pw"
End If
End Sub

Change pw to the actual password.
 
Upvote 0
That worked! You are awesome!!
Is it possible to have to re-protect itself if the value falls back under/less than 6? I noticed when the value fell, it remained un-protected. If it could re-protect if the value falls below 6 that would be PERFECT!!!
 
Upvote 0
Try

Code:
Private Sub Worksheet_Calculate()
If Range("B29").Value >= 6 Then
    Me.Unprotect Password:="pw"
    Range("B34").Locked = False
    Me.Protect Password:="pw"
Else
    Me.Unprotect Password:="pw"
    Range("B34").Locked = True
    Me.Protect Password:="pw"
End If
End Sub
 
Upvote 0
Genius!! You just made my day! Thank you very much!!! :)
If I wanted to repeat that same setup on the same worksheet to C29 and C34 would I just create another Private Sub and repeat it that way. Or is there an easier way to repeat that?
I was thinking of:
Private Sub Worksheet_Calculate2()
If Range("C29").Value >= 6 Then
Me.Unprotect Password:="pw"
Range("C34").Locked = False
Me.Protect Password:="pw"
Else
Me.Unprotect Password:="pw"
Range("C34").Locked = True
Me.Protect Password:="pw"
End If
End Sub
 
Upvote 0
Actually, nevermind....I think I figured it out.
Thanks for all your help. Much appreciated VoG!!
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,273
Members
449,219
Latest member
daynle

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