有人可以推荐一些计算单元格内点击次数的免费程序吗?
例如,假设这样的情况:我单击A1单元格,值显示为1,然后再次单击A1单元格,值显示为2,依此类推,如果我单击A3单元格,则单元格的单击计数显示为1,以此类推
如果像这样的事情可以实现一个宏在excel (2003请),请建议或任何其他免费程序,你可能知道,请让我知道。非常感谢您的帮助,并提前向您表示感谢。
发布于 2010-03-21 09:41:10
Excel没有用于鼠标左键单击的工作表事件。
它确实有一个'SelectionChange‘的事件,这个事件可以与一个API调用结合起来,检查是否点击了鼠标左键。
这段代码需要进入Project Explorer区域中的Sheet对象,以获得您要创建的工作表。
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尽管此代码可以工作,但即使用户没有单击鼠标左键,它也可以递增单元格值。
如果可能的话,我建议使用'BeforeDoubleClick‘事件。这是内置于Excel中的代码,比上面的代码更可靠。
为了增加单元格值,用户需要双击该单元格。
这段代码需要进入Project Explorer区域中的Sheet对象,以获得您要创建的工作表。
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 Subhttps://stackoverflow.com/questions/2482979
复制相似问题