在Excel中计数点击次数

有人可以推荐任何免费的程序,计算在单元格内单击的点击数量。

例如想象一下像电子表格一样我点击A1单元格的值显示1然后,我再次单击A1单元格的值显示2等等如果我点击A3单元格之间的点击计数单元格A3显示1等等

如果像这样的东西可以作为一个macros在Excel(2003年请)请build议或任何其他免费程序,您可能会意识到,请让我知道。 感谢您的帮助,并感谢您的提前。

Excel没有鼠标左键单击事件。

它确实有一个“SelectionChange”的事件,这可以与一个API调用相结合来检查鼠标左键是否被点击。

此代码需要进入工作表的“工程资源pipe理器”区域中的图表对象。

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim Key As Integer If Target.Count > 1 Then Exit Sub ''//If multiple cells selected with left click and drag ''// then take no action Key = GetKeyState(MOUSEEVENTF_LEFTDOWN) If Key And 1 Then If IsNumeric(Target.Value) Then Target.Value = Target.Value + 1 ''//Check to see if cell contains a number, before ''// trying to increment it Application.EnableEvents = False Target.Resize(1, 2).Select Application.EnableEvents = True ''//Resize the selection, so that if the cell is clicked ''// for a second time, the selection change event is fired again End If End If End Sub 

虽然这个代码有效,但即使用户没有点击鼠标,它也可以增加单元格的值。


如果可能,我build议使用“BeforeDoubleClick”事件。 这是内置于Excel中,比上面的代码更可靠。

为了增加单元格值,用户需要双击单元格。

此代码需要进入工作表的“工程资源pipe理器”区域中的图表对象。

 Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If IsNumeric(Target.Value) Then Target.Value = Target.Value + 1 ''//Check to see if cell contains a number, before ''// trying to increment it Application.EnableEvents = False Target.Resize(1, 2).Select Application.EnableEvents = True ''//Resize the selection, so that if the cell is clicked ''// for a second time, the selection change event is fired again Cancel = True ''//Stop the cell going into edit mode End If End Sub 

是的,这是可能的。 您可以使用此链接提供的VBA脚本的一些变体。 希望这可以帮助。