简体   繁体   中英

Hello, I am trying to lock the cells in an excel sheet based on the values in other sheet of the excel

I have tried various codes that seem to work perfectly for others but not in my case. Before i write any code the sheet, all the cells in my sheet appear as Locked anyways. I am stuck here and do not know what can be done here.

I tried this code but nothing seems to be locked,i can still do whatever i want in the sheet.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A1") = "Accepting" Then
        Range("B1:B4").Locked = False
    ElseIf Range("A1") = "Refusing" Then
        Range("B1:B4").Locked = True
    End If


End Sub

Locking a range will have no effect unless the sheet is also protected.

For instance Range("B1:B4").Locked = True won't work until you do YourWorksheet.Protect . You can unprotect it after by doing YourWorksheet.Unprotect .

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