这是我的代码。这是一个功能,当我单击一个未锁定的单元格时,它会将值增加一。我在让它始终运行时遇到问题。有时它会运行,有时我必须打开代码并在最后一个 END SUB 后按 Enter。我想要的是一个刷新此代码以便 VBA 工作的按钮。
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Key As Integer
If Target.Count > 1 Then Exit Sub
Key = GetKeyState(MOUSEEVENTF_LEFTDOWN)
If Key And 1 Then
If IsNumeric(Target.Value) Then
Target.Value = Target.Value + 1
Application.EnableEvents = False
Target.Resize(1, 2).Select
Application.EnableEvents = True
End If
Cancel = True
End If
End Sub