Note: The other languages of the website are Google-translated. Back to English
登陆  \/ 
x
or
x
注册  \/ 
x

or

如何双击单元格并在Excel中将该单元格值添加1?

本文将向您展示在Excel中双击将1自动添加到单元格值的方法。

双击一个单元格,然后在其中添加1个VBA代码


双击一个单元格,然后在其中添加1个VBA代码


以下VBA代码可以帮助您双击后将1加到单元格值中。 请执行以下操作。

1.右键单击工作表选项卡,双击该单元格值需要将其添加1。 然后点击 查看代码 从右键单击菜单中。

2.在弹出 Microsoft Visual Basic应用程序 窗口,将下面的VBA代码复制并粘贴到“代码”窗口中。

VBA代码:双击单元格值加1

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    On Error Resume Next
    If Not Intersect(Target, Range("A1")) Is Nothing Then
      Range("A1").Value = Range("A1").Value + 1
      Cancel = True
    End If
End Sub

备注:在代码中,A1是您将双击添加数字1的单元格。

3。 按 其他 + Q 同时按下键以关闭“ Microsoft Visual Basic for Applications”窗口。

现在,双击单元格A1将为现有值加1,如下图所示。


相关文章:


最佳办公效率工具

Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%

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

Office选项卡为Office带来了选项卡式界面,使您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Say something here...
symbols left.
You are guest
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.
    OW · 10 months ago
    What code would I you if I want to add 1 to multiple cells lets say E5:E15 but then add .5 or a different number to another group of cells like G5:515?
  • To post as a guest, your comment is unpublished.
    Stella · 1 years ago
    I cannot get this to work in multiple cells
    Tried using, but it did not work


    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    On Error Resume Next
    If Not Intersect(Target, Range("B2:L14")) Is Nothing Then
    Range("B2:L14").Value = Range("B2:L14").Value + 1
    Cancel = True
    End If
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Stella,
      Please apply the below VBA to solve the problem.

      Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      On Error Resume Next
      If Not Intersect(Target, Range("B2:L14")) Is Nothing Then
      Target.Value = Target.Value + 1
      Cancel = True
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Bill · 3 years ago
    If you want to increment any cell in a workbook cell by double clicking on that cell but only that cell, this code works:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    On Error Resume Next
    If Not Intersect(Target, Range(ActiveCell.Address)) Is Nothing Then
    ActiveCell.Value = ActiveCell.Value + 1
    Cancel = True
    End If
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Bill,
      Thank you for sharing.
      • To post as a guest, your comment is unpublished.
        BB · 3 years ago
        Thank You! that helped me a lot!
  • To post as a guest, your comment is unpublished.
    Steve · 3 years ago
    This is great! How do I do this for multiple cells? I type in "A1,A2" instead "A1", it makes both cells equal and adds 1 to both cells simultaneously. I'd like the cells to act independently.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Sorry I didn’t get your point.
      • To post as a guest, your comment is unpublished.
        Adam · 3 years ago
        Hello - agree with Steve this is great. I think what he would like (and me too) is to be able to add to the value of multiple different cells in the same tab by double clicking on them. He has amended the VBA formula so it says "A1,A2" instead of just "A1" however double clicking on "A1" adds 1 to both cells. Is it possible to change the formula so that multiple cells are included with the value of each only being increased when you click on it directly?
        • To post as a guest, your comment is unpublished.
          laura · 3 years ago
          maybe by making a table with a range name. and updating the formula to include that?
        • To post as a guest, your comment is unpublished.
          Steve · 3 years ago
          Basically, with the code above, if you double clicked on A1, it would add 1 to A1. If I changed A1 to A1:A2 in the Target Range, then if I double clicked on A1 or A2, it would add 1 to A1. What I wanted was to add 1 to A1 only if I double clicked on A1, and add 1 to A2 only if I double clicked on A2. I also did not want to add 1 to both cells.

          I think I have found what I was looking for:

          Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
          If Not Intersect(Target, Range("D5:BC56")) Is Nothing Then
          Cancel = True
          Range(Target.Address).Value = Val(Range(Target.Address).Value) + 1
          End If
          End Sub
          • To post as a guest, your comment is unpublished.
            Sophie · 3 years ago
            This code does not seem to work for me. Don't I have to specify which is the Target.Adress ?
          • To post as a guest, your comment is unpublished.
            crystal · 3 years ago
            Dear Steve,
            I got your point finally, and thank you for sharing.
  • To post as a guest, your comment is unpublished.
    Matt · 3 years ago
    Can we add a two digit number to the end of the date? for example i need to double click and add the current date and the next two digit number (20171030-01 then the next cell will show 20171030-02 upon double click)
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Matt,
      The code only supports the number format cell. It can't work as your data 20171030-01 is text format. Sorry about that.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Matt,
      The code only supports the number format cell. It can work as your data 20171030-01 is a text format. Sorry about that.