How to write a macro to count clicks in Excel?
Rightclick on the worksheet tab that should have this behavior and select view
code.
Paste this into the code window:
Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
Cancel = True
With Target.Offset(0, 1)
If IsNumeric(.Value) Then
.Value = .Value + 1
Else
Beep
End If
End With
End Sub
If you rightclick on A1, it'll add 1 to B1.
(You could use Worksheet_BeforeDoubleClick, too. But there isn't a single click
event.)
GoBoilerzz wrote:
Hello....I would like to write a macro/formula in Excel such that each click
in a cell will add 1 to another cell, ie the number of clicks will be
counted. It can be either a left or right click....Is this possible??
Thanks!!
Steve
--
Dave Peterson
|