Excel doesn't have a worksheet event for the mouse left click.
It does have an event for 'SelectionChange' and this can be combined with an API call to check if the left mouse button was clicked.
This code needs to go into the Sheet Object in the Project Explorer area for the worksheet that you are targeting.
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
''//If multiple cells selected with left click and drag
''// then take no action
Key = GetKeyState(MOUSEEVENTF_LEFTDOWN)
If Key And 1 Then
If IsNumeric(Target.Value) Then
Target.Value = Target.Value + 1
''//Check to see if cell contains a number, before
''// trying to increment it
Application.EnableEvents = False
Target.Resize(1, 2).Select
Application.EnableEvents = True
''//Resize the selection, so that if the cell is clicked
''// for a second time, the selection change event is fired again
End If
End If
End Sub
Although this code works, it can increment a cell value even if the user has not left clicked their mouse.
I would recommend using the 'BeforeDoubleClick' event instead if possible. This is built into Excel and is more reliable than the code above.
In order to increment a cell value, the user would need to double click on the cell.
This code needs to go into the Sheet Object in the Project Explorer area for the worksheet that you are targeting.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If IsNumeric(Target.Value) Then
Target.Value = Target.Value + 1
''//Check to see if cell contains a number, before
''// trying to increment it
Application.EnableEvents = False
Target.Resize(1, 2).Select
Application.EnableEvents = True
''//Resize the selection, so that if the cell is clicked
''// for a second time, the selection change event is fired again
Cancel = True
''//Stop the cell going into edit mode
End If
End Sub