以前锁定的单元格通过 Target.Row 值解锁
我正在尝试编写代码来锁定相对于目标行的单元格。 例如,如果我们将“优先级”列选择为“是”,则应锁定“Y1 列”。我有能力做到这一点。当我在下一行工作时,问题就出现了。如果我们在下一行中选择“优先级”列为“是”,则单元格 c3 被锁定,但单元格 C2 被解锁,如何使单元格 C2 保持锁定状态
到目前为止我的代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If target.column = 1 then
If sheet1.range("A" & Target.Row).value = "Yes" then
sheet1.range("C" & target.row).locked = true
activesheet.protect password:="pass"
else
sheet1.range("C" & target.row).locked = false
End if
如果我们在第 2 行上工作,则单元格 C2 被锁定,但如果我们处理第 3 行,然后单元格 C3 被锁定,但 C2 被解锁。我们怎样才能保持C2处于锁定状态
I am trying to write a code to Lock a cell with respect to target row.
In example, If we select Priority column as Yes then Column Y1 should be locked. I am able to do that. The problem comes when I work on next row. If we select Priority column as Yes in the next row, then cell c3 gets locked but cell C2 gets unlocked, how to keep the cell C2 as locked
My code so far :
Private Sub Worksheet_Change(ByVal Target As Range)
If target.column = 1 then
If sheet1.range("A" & Target.Row).value = "Yes" then
sheet1.range("C" & target.row).locked = true
activesheet.protect password:="pass"
else
sheet1.range("C" & target.row).locked = false
End if
If we work on Row 2 then cell C2 gets locked, but if we work on Row 3 then cell C3 gets locked but C2 gets unlocked. How can we keep C2 as locked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
工作表更改:锁定单元格
Sheet1
)之前解锁所有单元格。A Worksheet Change: Locking Cells
Sheet1
.