Visual Basic Code, Locking Cells depending on Value - V.03

Princess88

New Member
Joined
Apr 12, 2011
Messages
1
Hi,

I'm new to the forum, so I apologise if this is a ramble of non-sense!
- :confused:

I need to run a code for resource cover in the office - I need the sheet to lock the column where leave can be entered if the overall cover falls below 70%. The % cell is conditionally formatted to show as 'red' if the cover is less than 70%.

Essentially, I need it to be something along the lines of:

If [G37] = <70% Then [G6:G31].Locked

(obviously it will be more complex than that...but thats the gist of what I need it to do!!)

Also, is there a way for the code to run this separately for every column?

I really appreciate any help!

Princess88
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Here's one way:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
    For i = 1 To 10 ' columns A through J
        If Cells(37, i).Value < 0.7 Then
            Range(Cells(6, i), Cells(31, i)).Locked = True
        Else
            Range(Cells(6, i), Cells(31, i)).Locked = False
        End If
    Next i
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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