Excel - increase value at mouse click

AI Thread Summary
A VB code snippet is provided to increment the value in cell C8 by 1 each time cell C9 is double-clicked. The code utilizes the Worksheet_BeforeDoubleClick event, where setting Cancel to True prevents the cell from entering edit mode, allowing for multiple increments. While this method works effectively for double clicks, achieving the same functionality with a single click is more complex. It can be done using the SelectionChange event, but it has limitations based on the cursor's previous position. Alternatively, creating a link or button in C9 can also facilitate the increment action.
atferrari
Messages
8
Reaction score
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.
 
Computer science news on Phys.org
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.
 
Neat! Gracias.
 
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Back
Top