Lock some cells in row based on value in column A

libcat

New Member
Joined
Nov 30, 2021
Messages
10
Platform
  1. Windows
Hi everyone,

Can anyone help me come up with a VBA code? I've tried a million ideas that I found on mrexcel but can't seem to get them to work.

I need to unlock specific cells in a row based on a specific value in column A of the same row:

If A2 = In Process, unlock B2:C2, E2, and G2:AN2
And repeat for each row: If A3 = In Process, unlock B3:C3, E3, and G3:AN3.

If the value in column A value is any other value that "In Process", all cells in that row should stay locked.

Thanks in advance!
 
Alternatively, it might make sense to move BOTH inside the IF...THEN loop, as there is no reason to unprotect it if the condition is not met and aren't going to do anything.
The way you have it now will work, but will needlessly unprotect/protect it when nothing is being triggered to happen.

Here is what that undated code would look like:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Long
    Dim rng As Range
    If Not Intersect(Target, Range("a:a")) Is Nothing Then
        ActiveSheet.Unprotect ""
        i = Target.Row
        Set rng = Union(Range(Cells(i, 2), Cells(i, 3)), Cells(i, 5), Range(Cells(i, 7), Cells(i, 35)))
        If Cells(i, 1) = "In Process" Then
            rng.Locked = False
        Else
            rng.Locked = True
        End If
        ActiveSheet.Protect ""
    End If
End Sub
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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