Link to home
Start Free TrialLog in
Avatar of Jase Alexander
Jase AlexanderFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA Incrementing the value in a specific cell by 1 when left mouse is clicked inside cell

Hi Experts

I wonder if you can help

Im writing a simple stock control system and for user friendliness was wondering if there was anyway using VBA that when the mouse is left clicked in a certain cell, sat A1, the number is incremented by 1

Subsequently, if the mouse is right clicked in the cell A1, then it would decrease by 1

Is this possible?

Any advice would be welcome

J
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

The only click events for a worksheet are BeforeDoubleClick and BeforeRightClick, perhaps you could use them?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Address = "$A$1" Then
        Cancel = True
        Target.Value = Target.Value + 1
    End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Address = "$A$1" Then
        Cancel = True
        Target.Value  = Application.Max(0, Target.Value - 1)
    End If

End Sub

Open in new window

Please see my The magical floating ActiveX control article. It will show you how to temporarily float an ActiveX checkbox over a cell or cells, and that textbox will respond to a single right- or left-click.
Avatar of Jase Alexander

ASKER

HI Guys

Thank you for the response

Sam - thank you - It worked perfect

regards
Jase
You are most welcome, Jase.