Excel - increase value at mouse click

  • Thread starter atferrari
  • Start date
  • #1
atferrari
8
0
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.
 

Answers and Replies

  • #2
CompuChip
Science Advisor
Homework Helper
4,309
49
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.
 
  • #3
atferrari
8
0
Neat! Gracias.
 

Suggested for: Excel - increase value at mouse click

Replies
6
Views
118
Replies
21
Views
2K
Replies
6
Views
234
  • Last Post
Replies
2
Views
550
  • Last Post
Replies
2
Views
379
Replies
1
Views
472
Replies
3
Views
358
Replies
13
Views
481
  • Last Post
Replies
10
Views
917
Top