本帖最后由 huchuanxing 于 2016-10-30 16:03 编辑
工作表中添加以下VBA代码后,在单元格输入内容后即会自动锁定,我想可否把它修改一下,让工作簿中的其它工作表也能在输入内容后自动锁定?
Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error Resume Next With Target.Range("a1") If .Value <> "" Then PW = InputBox("修改内容请输入密码:") If PW <> "123" Then Cells(1, 1).Select Else Exit Sub End If End If End With End Sub
这样修改一下可能更严谨一些
- Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
- On Error Resume Next
- Application.EnableEvents = False
- With Target.Range("a1")
- If .Value <> "" Then
- PW = InputBox("修改内容请输入密码:")
- If PW <> "123" Then
- Cells(Cells(Rows.Count, .Column).End(3).Row + 1, .Column).Select
- End If
- End If
- End With
- Application.EnableEvents = True
- End Sub
复制代码
|