在sheet1里增加一个CommandButton1,Alt+F11打开VBE双击左边的sheet1将下面代码复制到中间的代码区.关闭VBE.将CommandButton1结束设计模式即可.
如需要请发电邮到
[email protected]Option Explicit
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Can input" Then
CommandButton1.Caption = "Can NOT input"
Else
CommandButton1.Caption = "Can input"
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Intersect(Target, Range("A1:D10")) 'A1:D10表示一定条件不能编辑的区域.
If rng Is Nothing Then Exit Sub
If CommandButton1.Caption = "Can input" Then
Exit Sub
Else
Range("D11").Select '"D11"表示当选取不能编辑区域时,默认选择储存格.
End If
End Sub