Excel - increase value at mouse click

  • Thread starter atferrari
  • Start date
  • #1
8
0

Main Question or Discussion Point

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,302
47
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
8
0
Neat! Gracias.
 

Related Threads on Excel - increase value at mouse click

  • Last Post
7
Replies
151
Views
8K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
5
Views
9K
Replies
8
Views
1K
  • Last Post
Replies
14
Views
1K
  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
5
Views
898
  • Last Post
Replies
10
Views
6K
Top