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 for Applications 窗口,將下面的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 · 8 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.