简体   繁体   中英

How to lock a cell based off of a value from another cell

I have a sheet that has column B. the states a disposition of our product released, hold ect.. column A. states what has been done with this product ie shipped, in storage ect. I need to have column A. to be locked if column B. is set to "Hold" I am pretty new to this coding and so I have almost no idea where to start or if its even possible.

Pasted in VBE under sheet that you want this rule to apply to...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A:A")) Is Nothing Then
    If Target.Count = 1 Then
        If Target.Offset(, 1) = "Hold" Then
            Application.EnableEvents = False
                Application.Undo
                MsgBox "Cell on Hold. Reverting changes", vbCritical
            Application.EnableEvents = True
        End If
    End If
End If

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM