# Excel - increase value at mouse click

atferrari
I forgot long time ago the little I knew of VB applied to Excel.

Can anyone give a snippet of VB code to get the value in cell C8 to increasing by n every time I click the mouse on cell C9?

I recall that being possible but I am clueless now.

Gracias for any help.

Homework Helper
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target = Range("C9") Then
Range("C8").Value = Range("C8").Value + 1
Cancel = True
End If
End Sub

This works on double click. Setting Cancel to True prevents the cell from going into edit mode, so you can double click it again.

Doing it on click is a little harder, you can use SelectionChange for that, but that will only work if the cursor was not previously in C9. Otherwise, you can make a link or button in C9 and use that, but this is the most basic solution.

atferrari
Neat! Gracias.