提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何在Excel工作表中創建秒錶?

如果工作表中有秒錶,您將知道完成工作的時間。 如何在具有開始,停止和重置按鈕的工作表中創建秒錶,如下面的屏幕截圖所示? 如果單擊“開始”按鈕,它將啟動時間,如果您單擊“停止”按鈕,它將停止時間,並且“重置”按鈕可以幫助您重置時間。 本文將介紹如何在Excel中創建一個簡單且方便的秒錶。

doc創建秒錶1

使用VBA代碼創建帶有三個按鈕的秒錶


給日期時間添加幾小時/分鐘/秒:

Kutools for Excel's 添加時間/分鐘/秒至日期 功能,您可以快速添加或減去數小時,分鐘或秒鐘的日期。 現在點擊下載並免費試用Kutools for Excel!

doc創建秒錶10

Kutools for Excel:比200方便的Excel加載項,可以在60天免費試用。 下載並免費試用現在!


使用VBA代碼創建帶有三個按鈕的秒錶

要使用三個按鈕創建秒錶,開始,停止和重置,請按照以下步驟逐一進行。

首先,插入三個命令按鈕。

1。 點擊 開發人員 > 插入 > 命令按鈕,看截圖:

doc創建秒錶2

2。 然後拖動鼠標繪製一個按鈕,插入按鈕後,可以更改按鈕標題,請點擊 開發人員 > 屬性 屬性 對話框中,輸入新的標題“開始“這個按鈕在文本框旁邊 標題,看截圖:

doc創建秒錶3  2 doc創建秒錶4

3。 重複上述兩個步驟來插入其他兩個按鈕並將它們標記為“停止“和”重啟“,看截圖:

doc創建秒錶5

4。 插入按鈕後,應通過單擊退出設計模式 開發人員 > 設計模式.

其次,創建一個VBA代碼。

5。 然後,右鍵單擊當前工作表選項卡,然後選擇 查看代碼,在彈出 Microsoft Visual Basic for Applications 窗口,請將以下代碼複製並粘貼到 模塊:

VBA代碼:創建秒錶:

Public StopIt As Boolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("C2") = 0 Then
  StartTime = Timer
  PauseTime = 0
  LastTime = 0
Else
  StartTime = 0
  PauseTime = Timer
End If
StartIt:
  DoEvents
  If StopIt = True Then
    LastTime = TotalTime
    Exit Sub
  Else
    FinishTime = Timer
    TotalTime = FinishTime - StartTime + LastTime - PauseTime
    TTime = TotalTime * 100
    HM = TTime Mod 100
    TTime = TTime \ 100
    hh = TTime \ 3600
    TTime = TTime Mod 3600
    MM = TTime \ 60
    SS = TTime Mod 60
    Range("C2").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
    If ResetIt = True Then
      Range("C2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
      LastTime = 0
      PauseTime = 0
      End
    End If
    GoTo StartIt
  End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  StopIt = True
End Sub
Private Sub CommandButton3_Click()
  Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
  LastTime = 0
  ResetIt = True
End Sub

doc創建秒錶6

注意:在上面的代碼中, C2 是秒錶時間將被插入的單元格,而 CommandButton1, CommandButton2, CommandButton3 是按鈕名稱,您可以從中查看確切的按鈕名稱 名稱框,看截圖:

doc創建秒錶7

第三,格式化秒錶時間單元格。

6。 然後你應該格式化時間單元格 文本 格式,您可以根據需要更改單元格大小,字體,字體顏色,背景等,請參閱截圖:

doc創建秒錶8

7。 完成上述步驟後,從現在開始,點擊 開始 按鈕,時間將會開始,然後點擊 停止 按鈕,它會停止時間, 重啟 按鈕將重置時間,請參閱截圖:

doc創建秒錶9


演示:使用VBA代碼創建帶有三個按鈕的秒錶


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
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.
    Pierre Roux · 1 months ago
    HI. I have created the stopwatch, but need to be able to have the various intervals between the start and stop to be saved to be able to reflect them as a time and motion study. Any tips on how to do that?
  • To post as a guest, your comment is unpublished.
    Nhoeun Nou · 7 months ago
    Thank for your tip, It was running smoothly but when I input any data in this sheet It's stopped running, We need it keep running awhile input data How we can fix this problem?
    • To post as a guest, your comment is unpublished.
      skyyang · 7 months ago
      Hello, Nhoeun,
      May be there in not a good way for solving your problem. When you edit a cell, it will interrupt the currently executed macro.
      If you have any other good method, please comment here!
      Thank you!
  • To post as a guest, your comment is unpublished.
    Yuval · 9 months ago
    Hi, I'm using this stopper but quite often the numbers in the display cell ("C2") start fricking out and go off - they show minus signs, the digits are incorret and the count is lost. It usually happens after about an hour or more but sometimes even before an hour goes by. Is this a common bug? and if yes, is there a way to fix it? I did remove the .00 (i.e. the miliseconds) from the code by simply erasing the: & "." & Format(0, "00") line wherever it appears - does that have to do anything with this problem?
  • To post as a guest, your comment is unpublished.
    Damian · 1 years ago
    Is there any way to have the timer reset the count to zero but still keep the timer running? Ie. When I press Reset, I don't want to have to press Start again for the time to tick up.
  • To post as a guest, your comment is unpublished.
    Vivek Nath · 1 years ago
    Is it possible to automatically stop the timer when screen locks and start the timer automatically when we unlock the computer?
  • To post as a guest, your comment is unpublished.
    Tor-Bjørn Øverbø · 1 years ago
    Great, but is it possible to run 2 clocks in the same sheet? have made a second clock with new start, stop and reset buttom, but when starting the second clock the first one stops....
    • To post as a guest, your comment is unpublished.
      Vishal Sharma · 1 years ago
      same here can you able to find cure of this
      • To post as a guest, your comment is unpublished.
        skyyang · 1 years ago
        Hello, friends,
        This method is only applied to one set of buttons in a worksheet.
        If there are other good ideas, please comment here.
  • To post as a guest, your comment is unpublished.
    Melissa Stranko · 1 years ago
    Is there any way to get the timer to count up or down to a specific time? I want to keep the start, stop, and reset buttons, but I need it to count up to one minute one second only, once I press start. Or count down from one minute one second to zero (01:01). Thanks for your help!
  • To post as a guest, your comment is unpublished.
    Guest · 1 years ago
    Try XNote Stopwatch.
  • To post as a guest, your comment is unpublished.
    Prashant · 2 years ago
    Have tried to create the stop watch using the same codes in Forms. The timer starts perfectly fine but does not stop . Please suggest how to replicate the same in forms
  • To post as a guest, your comment is unpublished.
    Paulo G. · 2 years ago
    This was a great help and very easy to follow the steps.
  • To post as a guest, your comment is unpublished.
    Gnarlsagan · 2 years ago
    Thank you for this post, it was very helpful. However, is there a way to tweak the code to make it so the timer does not stop when a cell is being edited? Ideally I would like to hit "Start," make a number of changes to a range of cells on the same tab, and then hit "Stop" for the total time elapsed. Any advice on this would be greatly appreciated!