Lock range of cells depending on value in final cell in range

ketarix

New Member
Joined
Aug 28, 2015
Messages
1
Hi,

Firstly let me state that I am not proficient with VBA, I need spoon feeding here I am afraid so please be my saviour(s)!

The issue I am having is that I am trying to create a medical notes sheet where the first lot of cells lock once a value is entered in a specific cell.

I need this to work either indefinitely, or to a very high number of rows down.

So Columns "A" to "I" need to lock once "I" has "Yes" entered in it. I have found macros to lock the entire row, but I have further columns beyond I that which need to stay unlocked.

I am password protecting the sheet, as this seems to be a necessity if my failed attempt to find a solution is anything to go by.

Save me!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,

Firstly let me state that I am not proficient with VBA, I need spoon feeding here I am afraid so please be my saviour(s)!

The issue I am having is that I am trying to create a medical notes sheet where the first lot of cells lock once a value is entered in a specific cell.

I need this to work either indefinitely, or to a very high number of rows down.

So Columns "A" to "I" need to lock once "I" has "Yes" entered in it. I have found macros to lock the entire row, but I have further columns beyond I that which need to stay unlocked.

I am password protecting the sheet, as this seems to be a necessity if my failed attempt to find a solution is anything to go by.

Save me!
Hi ketarix,

For this to work you will first need to select ALL cells-->Format Cells-->Protection-->Untick "Locked". This is because otherwise the moment you protect the sheet ALL cells will be protected. Once you have done that you can try the following Worksheet_Change macro. Try it out in a COPY of the workbook. Right-click on the tab name and select View Code. In the new window that opens simply copy / paste my code in. The comments in the code should explain what it is doing. Update the bold red part with the correct password:

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
' If your target is in column I then...
If Not Intersect(Target, Range("I:I")) Is Nothing Then
    ' If the target value is Yes (case insensitive) and A:I of the target row are all filled then...
    If UCase(Target.Value) = "YES" And Application.WorksheetFunction.CountA(Range("A" & Target.Row, "I" & Target.Row)) = 9 Then
        ' Unprotect the sheet with the password
        ActiveSheet.Unprotect "PASSWORD"
        ' Format A:I of the target row as "Locked"
        Range("A" & Target.Row, "I" & Target.Row).Locked = True
        ' Reprotect the sheet with the password
        ActiveSheet.Protect "PASSWORD"
    End If
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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