简体   繁体   English

您好,我正在尝试根据Excel其他工作表中的值锁定Excel工作表中的单元格

[英]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 . 例如, Range("B1:B4").Locked = True在您执行YourWorksheet.Protect之前不会YourWorksheet.Protect You can unprotect it after by doing YourWorksheet.Unprotect . 您可以在执行YourWorksheet.Unprotect之后取消保护它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据工作表中的其他值将excel中的值复制到另一工作表 - Copying values in excel to another sheet, based on other values in the sheet vba / excel-根据用户输入到sheet1的单元格中,从sheet2的值填充sheet1中的单元格 - vba/excel - populate cells in sheet1 from values in sheet2 based on user input into cells on sheet1 我正在尝试将一行中的特定列复制到另一个 excel 工作表,基于它满足两个标准 - I am trying to copy specific columns in a row to another excel sheet based on it meeting two criteria Excel-基于单元格为标签创建新表 - Excel - create new sheet for label based on cells Excel VBA-尝试根据值将值复制到摘要表 - Excel VBA- Trying to copy values to summary sheet based on a value excel片的着色细胞 - coloring cells of excel sheet 将单元格值从Excel工作表复制到数组中 - Copy Cells values from Excel sheet into an array Excel-跨表格检查单元格的值 - Excel - Checking Values of Cells Across Sheet 如果包含我正在比较的值的单元格,我如何在 Excel 工作表中返回最小值,这些值是由函数创建的 - How can I return a minimum value in excel work sheet if the cells containing the values I am comparing , the values were created by a function 有没有办法在编辑共享点上的 Excel 工作表后锁定单元格? - Is there a way to lock cells after editing an excel sheet that's on sharepoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM