'记录下原单元格位置
Public strAddress
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'取消表保护
ActiveSheet.Unprotect
If Not IsEmpty(strAddress) Then
'如果是A列出来,则相应改B
If Left(strAddress, 3) = "$A$" Then
If Range(strAddress).Value = "是" Then
With Cells(Mid(strAddress, 4, Len(strAddress)), "B").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="否"
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
Else
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="是,否"
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
End If
End If
End If
'如果是b列出来,则相应改c列是否锁定
If Left(strAddress, 3) = "$B$" Then
If Range(strAddress).Value = "否" Then
Cells(Mid(strAddress, 4, Len(strAddress)), "c").Locked = True
Else
Cells(Mid(strAddress, 4, Len(strAddress)), "c").Locked = False
End If
End If
strAddress = ActiveCell.Address
'保护表
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
需要先选中A、B、C列,按Ctrl+1,在保护标签下,取消锁定
然后再在审阅中,保护工作表
再在本工作表中,输入以上代码就可以了
这个只能用宏代码控制