提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何计算Excel中指定单元格的总点击次数?

本文正在讨论如何计算Excel中指定单元格的总点击次数。

用VBA代码计算指定单元中的总点击次数

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

用VBA代码计算指定单元中的总点击次数


请按照以下步骤计算Excel中指定单元格的总点击次数。

1。 在工作表中包含您需要计算总点击次数的单元格,右键单击工作表选项卡,然后单击 查看代码 从上下文菜单。

2。 在里面 Microsoft Visual Basic for Applications 窗口,请复制并粘贴下面的VBA代码到代码窗口。

VBA代码:统计Excel中指定单元格的总点击次数

Public xRgS, xRgD As Range
Public xNum As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRgS = Range("E2")
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Range("H2")
    If xRgD Is Nothing Then Exit Sub
    If Intersect(xRgS, Target) Is Nothing Then Exit Sub
    xNum = xNum + 1
    xRgD.Value = xNum
End Sub

注意:在代码中,E2是您需要计算其总点击次数的单元格,H2是计数的输出单元格。 请根据需要更改它们。

3。 按 其他 + Q 键关闭 Microsoft Visual Basic for Applications 窗口。

从现在开始,当在这个指定的工作表中单击单元格E2时,总单击将在单元格H2中自动填充,如下面的屏幕截图所示。 例如,如果单击单元格E2 5次,则单元格H5中将显示编号2。


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Rennan Farias · 1 months ago
    Como zerar a contagem? How to reset the score?
  • To post as a guest, your comment is unpublished.
    Barbara · 6 months ago
    Can you provide a code that allows counting clicks from A2, B2 cells through A14, B14 cells. Thanks in advance.
    • To post as a guest, your comment is unpublished.
      crystal · 4 months ago
      Hi Barbara,
      Do you mean counting the total clicks in range A2:B14? Or clicks for each cell in range A2:B14?
  • To post as a guest, your comment is unpublished.
    Andrés · 8 months ago
    Hola
    Hay alguna manera de programar el conteo de clicks de acuerdo a la fecha, es decir programar varias celdas para que cuenten con la fecha del día?
  • To post as a guest, your comment is unpublished.
    Demetrius · 10 months ago
    Hello, there is a way to back the counting for any number that I want? For exemple: I'd made 5 clicks, but i just wanted 3. So I change the number in the cell to 3, and when I click again, it continue from 3.
    Thank for the code!
  • To post as a guest, your comment is unpublished.
    Guido · 1 years ago
    Thank you for the code, very useful.
    I'm not a programmer and I would like to know how to extend this process to every line. That is to say, not only E2>H2 but also E3>H3, E4>H4, and so on.
    Is there a code for this?


    Thank you in advance!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Guido,

      The below VBA code can help you to solve the problem. Please have a try. Thanks for your comment.
      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim xRgArray As Variant
      Dim xNum
      Dim xStrR, xStrS, xStrD As String
      Dim xRgS, xRgD As Range

      Dim xFNum As Long
      xRgArray = Array("E2,H2", "E3,H3", "E4,H4", "E5,H5", "E6,H6")
      On Error Resume Next
      If Target.Cells.count > 1 Then Exit Sub
      For xFNum = LBound(xRgArray) To UBound(xRgArray)
      xStrR = xRgArray(xFNum)
      xStrS = ""
      xStrS = Left(xStrR, 2)
      xStrD = ""
      xStrD = Right(xStrR, 2)
      Set xRgS = Nothing
      Set xRgS = Range(xStrS)
      If TypeName(xRgS) <> "Nothing" Then
      Set xRgD = Nothing
      Set xRgD = Range(xStrD)
      If TypeName(xRgD) <> "Nothing" Then
      If TypeName(Intersect(xRgS, Target)) <> "Nothing" Then
      xRgD.Value = xRgD.Value + 1
      End If
      End If
      End If
      Next
      End Sub
      • To post as a guest, your comment is unpublished.
        Ruth · 1 years ago
        Thanks for this. I tried and it worked, however it only worked only until certain number of cells, how can we extend this code until the end of the cells? for example i type in this code below and it only works until "G9,G9". Thanks


        Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim xRgArray As Variant
        Dim xNum
        Dim xStrR, xStrS, xStrD As String
        Dim xRgS, xRgD As Range

        Dim xFNum As Long
        xRgArray = Array("C4,C4", "D4,D4", "E4,E4", "F4,F4", "G4,G4", "C6,C6", "D6,D6", "E6,E6", "F6,F6", "G6,G6", "C7,C7", "D7,D7", "E7,E7", "F7,F7", "G7,G7", "C8,C8", "D8,D8", "E8,E8", "F8,F8", "G8,G8", "C9,C9", "D9,D9", "E9,E9", "F9,F9", "G9,G9", "C10,C10", "D10,D10", "E10,E10", "F10,F10", "G10,G10", "C11,C11", "D11,D11", "E11,E11", "F11,F11", "G11,G11", "C14,C14", "D14,D14", "E14,E14", "F14,F14", "G14,G14", "C15,C15", "D15,D15", "E15,E15", "F15,F15", "G15,G15", "C16,C16", "D16,D16", "E16,E16", "F16,F16", "G16,G16", "C17,C17", "D17,D17", "E17,E17", "F17,F17", "G17,G17", "C18,C18", "D18,D18", "E18,E18", "F18,F18", "G18,G18", "C20,C20", "D20,D20", "E20,E20", "F20,F20", "G20,G20")
        On Error Resume Next
        If Target.Cells.count > 1 Then Exit Sub
        For xFNum = LBound(xRgArray) To UBound(xRgArray)
        xStrR = xRgArray(xFNum)
        xStrS = ""
        xStrS = Left(xStrR, 2)
        xStrD = ""
        xStrD = Right(xStrR, 2)
        Set xRgS = Nothing
        Set xRgS = Range(xStrS)
        If TypeName(xRgS) <> "Nothing" Then
        Set xRgD = Nothing
        Set xRgD = Range(xStrD)
        If TypeName(xRgD) <> "Nothing" Then
        If TypeName(Intersect(xRgS, Target)) <> "Nothing" Then
        xRgD.Value = xRgD.Value + 1
        End If
        End If
        End If
        Next
        End Sub
        • To post as a guest, your comment is unpublished.
          crystal · 1 years ago
          Hi Ruth,
          The code is hard to optimized for meeting your needs. Sorry about that.
  • To post as a guest, your comment is unpublished.
    Dennis · 1 years ago
    How can you "reset" the counter?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Dennis,
      Please add the below VBA code at the end of the original code. Every time you run this code, the counting will be reset to 0. Thank you for your comment.

      Sub ClearCount()
      xRgD.Value = ""
      xNum = 0
      End Sub