作者:乔山办公网日期:
返回目录:excel表格制作
你少了一句制end if
ActiveSheet.Unprotect
Cells.Locked = False '先把所有单元格设置为百不锁定的
For i = 3 To 63
If Cells(i, 1) = "正确" Then Cells(i, 2).Locked = True
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
也可以改成以下代码度
ActiveSheet.Unprotect
Cells.Locked = False '先把所有单元格设置为不锁定的
For i = 3 To 63
If Cells(i, 1) = "正确" Then Cells(i, 2).Locked = True
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Me.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
注意:AllowFiltering:=True
'试试这样看行抄不行
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("a1").Locked = True Then
If Range("a1") = "" Then
Cells.Select
Selection.Locked = False
End If
End If
Me.Unprotect ("1") '撤销工作表保护,百123为密码度
If Target <> "" Then
Target.Locked = True
End If
Me.Protect ("1") '保护工作表
ActiveSheet.Unprotect
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target <> "" Then
ActiveSheet.Unprotect
End If
End Sub
可以使用project方法,保护工作表。另外,要先使zhidao用locked属性和formulahidden来锁定和隐藏需要锁定内或者隐藏的单元格区域容。
要填数据的可以不锁定,需要锁定的部分锁定并保护工作表了之后才可以的。