vba 锁定与解锁单元格
发布网友
发布时间:2022-04-29 23:40
我来回答
共1个回答
热心网友
时间:2022-06-26 04:48
Sub Macro1()
'当D1列显示为“正确”时,用VBA锁定A1、B1、C1列的数据,
'下面空白处a2\b2\c2\d2可以自由录入数据
Dim ir As Integer
Dim c As Range
ActiveSheet.Unprotect
ir = [a65536].End(xlUp).Row
Cells.Locked = False
For Each c In Range("d1:d" & ir)
If c.Value = "正确" Then Range("A" & c.Row & ":C" & c.Row).Locked = True
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub