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.
 
Thread 'Urgent: Physically repair - or bypass - power button on Asus laptop'
Asus Vivobook S14 flip. The power button is wrecked. Unable to turn it on AT ALL. We can get into how and why it got wrecked later, but suffice to say a kitchen knife was involved: These buttons do want to NOT come off, not like other lappies, where they can snap in and out. And they sure don't go back on. So, in the absence of a longer-term solution that might involve a replacement, is there any way I can activate the power button, like with a paperclip or wire or something? It looks...
I came across a video regarding the use of AI/ML to work through complex datasets to determine complicated protein structures. It is a promising and beneficial use of AI/ML. AlphaFold - The Most Useful Thing AI Has Ever Done https://www.ebi.ac.uk/training/online/courses/alphafold/an-introductory-guide-to-its-strengths-and-limitations/what-is-alphafold/ https://en.wikipedia.org/wiki/AlphaFold https://deepmind.google/about/ Edit/update: The AlphaFold article in Nature John Jumper...
Back
Top