View Full Version : Excel - increase value at mouse click
atferrari
Jan28-11, 04:07 AM
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.
CompuChip
Jan28-11, 05:56 AM
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
Jan29-11, 02:39 AM
Neat! Gracias.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.