Hello all. I am trying to get help with locking/unlocking cells. There is plenty of information here on how to lock/unlock cells, rows, and columns with VBA if all the cells are on the same sheet. However, in my case, I need to be able to unlock specific cells on Sheet4 after the final entry on Sheet3.
This is what I have to lock/unlock cells on the same sheet.
This code works perfectly for cells on the same sheet. When a value is entered in the cell in column N, it locks the entire current row being worked on, and unlocks cells B,C,D,E,F,G,I,J,K and M on the next line for data entry.
When the user gets to line 5000, I want to lock row 5000, and unlock cells B,C,D,E,F,G,I,J,K and M on row 6 in Sheet4. This is the part I cannot get working. I don't know if This code can be manipulated, or if it needs to be it's own separate lines of code to work.
Thank you in advance,
Jim
This is what I have to lock/unlock cells on the same sheet.
VBA Code:
Dim p As Range, z As Range
Set p = Range("N6:N4999")
Set p = Intersect(Target, p)
If Not p Is Nothing Then
Application.EnableEvents = False
For Each z In p
Select Case True
Case 14 = z.Column 'N
If z.Value <> "" Then
Check = MsgBox("Are your entries correct?" & vbCrLf & "After entering yes, These values CANNOT be changed.", vbYesNo + vbQuestion, "Cell Lock Notification")
If Check = vbYes Then
Target.Rows.EntireRow.Locked = True
Cells(z.Row + 1, "B").Locked = False
Cells(z.Row + 1, "C").Locked = False
Cells(z.Row + 1, "D").Locked = False
Cells(z.Row + 1, "E").Locked = False
Cells(z.Row + 1, "F").Locked = False
Cells(z.Row + 1, "G").Locked = False
Cells(z.Row + 1, "I").Locked = False
Cells(z.Row + 1, "J").Locked = False
Cells(z.Row + 1, "K").Locked = False
Cells(z.Row + 1, "M").Locked = False
If Cells(z.Row, "R").Value <> "" Then Copyemail 'R
If Cells(z.Row, "S").Value <> "" Then ThisWorkbook.Save 'S
With Me
.Parent.Activate
.Activate
.Range("B" & Rows.Count).End(xlUp).Offset(1).Activate
End With
Else
Cells(z.Row, "N").Value = ""
End If
End If
Case Else
End Select
Next z
End If
This code works perfectly for cells on the same sheet. When a value is entered in the cell in column N, it locks the entire current row being worked on, and unlocks cells B,C,D,E,F,G,I,J,K and M on the next line for data entry.
When the user gets to line 5000, I want to lock row 5000, and unlock cells B,C,D,E,F,G,I,J,K and M on row 6 in Sheet4. This is the part I cannot get working. I don't know if This code can be manipulated, or if it needs to be it's own separate lines of code to work.
Thank you in advance,
Jim