提示:其它语言是由 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。 支持所有语言。 在您的企业或组织中轻松部署。 全功能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.
    Pierre Roux · 9 days 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 · 6 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 · 6 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 · 8 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!