如何在 Excel 工作表中创建秒表
如果您曾经需要一个简单实用的 Excel 计时工具,那么本教程非常适合您。秒表可以为您的电子表格增添实用功能,无论您是在锻炼期间追踪时间、估算流程时长,还是仅仅记录时间。
在本教程中,我们将向您展示如何使用 Excel 的内置功能和公式来创建计时器。即使您没有任何编程经验或精通 Excel 技能,也可以跟着教程一起学习。我们将从零开始,逐步指导您完成每个步骤,确保您完全理解整个过程。
在 Excel 工作表中创建秒表
在这里,我们将首先插入三个命令按钮,然后在工作表中插入 VBA 代码来完成任务。让我们通过一个简单的过程来了解如何在 Excel 工作表中创建秒表。
步骤 1
考虑任何 Excel 工作簿。首先,点击"开发人员",然后点击"插入",并选择 ActiveX 控件下的命令按钮。
开发人员 > 插入 > 命令按钮。

步骤 2
然后绘制一个适当大小的命令按钮。然后右键单击该按钮并选择属性。然后点击"标题",并输入起始值。
绘制 > 右键单击 > 属性 >标题。

步骤 3
然后重复上述步骤,创建两个新按钮,分别名为"stop"和"reset",并退出设计模式。

步骤 4
现在右键单击工作表名称,然后选择"查看代码"以打开 VBA 应用程序,并将以下代码复制到文本框中。
Alt + F11 > 复制。

示例
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
代码中的 c2 单元格是我们插入秒表的位置。
步骤 5
然后使用 Alt+Q 关闭 VBA 应用程序。然后使用名称框将"Start"、"Stop"和"Reset"按钮分别重命名为 CommandButton1、CommandButton1 和 CommandButton1。
步骤 6
然后点击单元格 C2,并将其格式设置为文本。

以上就是如何在 Excel 工作表中创建秒表的方法。
总结
在本教程中,我们通过一个简单的示例演示了如何在 Excel 工作表中创建秒表来突出显示特定数据集。
相关文章
有用资源
excel 参考教程 - 该教程包含有关 excel 的更多信息:https://www.cainiaomax.com/excel/

