ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to write a macro to count clicks in Excel? (https://www.excelbanter.com/excel-programming/309955-how-write-macro-count-clicks-excel.html)

GoBoilerzz

How to write a macro to count clicks in Excel?
 
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[_3_]

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



All times are GMT +1. The time now is 09:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com