请问各位老师 在excel表格中如何才能加入一个计时器呢,可以点击开始计时,结束计时的那种,显示/时/分/的
发布网友
发布时间:2022-05-01 18:51
我来回答
共1个回答
热心网友
时间:2023-10-24 01:56
需要用到VBA编程,以下是前人的留贴,供参考
操作步骤:
1、在Excel工作表里按Alt+F11,打开VBA编程界面
2、在VBA编程界面的工具栏,第二个按钮拉下来选模块
3、在左边栏的你需要计时器的那个工作表名字上双击,打开右边的程序书写区域
4、把下面的程序代码粘贴进去
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B1")) Is Nothing) Then
[B1] = "开始时间"
[C1] = Format(Now(), "Hh:mm:Ss")
[D1] = Timer
[D1].Font.ColorIndex = 2
[B2:D3].ClearContents
End If
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B2")) Is Nothing) Then
[B2] = "结束时间"
[C2] = Format(Now(), "Hh:mm:Ss")
[D2] = Timer
[D2].Font.ColorIndex = 2
[B3] = "总共用时"
[C3] = Format([D2] - [D1], "#0.00")
[D3] = "秒"
End If
Target.Offset(1, 0).Select
End Sub
5、关闭VBA编程界面回到工作表
6、双击B1开始计时,双击B2终止计时,用时结果在C3单元格
(特别提醒:要在Exce中通过菜单“工具-宏-安全性”把宏的安全级别设为中或低以允许宏的运行,否则宏不能运行也得不到你要的结果)
热心网友
时间:2023-10-24 01:56
需要用到VBA编程,以下是前人的留贴,供参考
操作步骤:
1、在Excel工作表里按Alt+F11,打开VBA编程界面
2、在VBA编程界面的工具栏,第二个按钮拉下来选模块
3、在左边栏的你需要计时器的那个工作表名字上双击,打开右边的程序书写区域
4、把下面的程序代码粘贴进去
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B1")) Is Nothing) Then
[B1] = "开始时间"
[C1] = Format(Now(), "Hh:mm:Ss")
[D1] = Timer
[D1].Font.ColorIndex = 2
[B2:D3].ClearContents
End If
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B2")) Is Nothing) Then
[B2] = "结束时间"
[C2] = Format(Now(), "Hh:mm:Ss")
[D2] = Timer
[D2].Font.ColorIndex = 2
[B3] = "总共用时"
[C3] = Format([D2] - [D1], "#0.00")
[D3] = "秒"
End If
Target.Offset(1, 0).Select
End Sub
5、关闭VBA编程界面回到工作表
6、双击B1开始计时,双击B2终止计时,用时结果在C3单元格
(特别提醒:要在Exce中通过菜单“工具-宏-安全性”把宏的安全级别设为中或低以允许宏的运行,否则宏不能运行也得不到你要的结果)
热心网友
时间:2023-10-24 01:56
需要用到VBA编程,以下是前人的留贴,供参考
操作步骤:
1、在Excel工作表里按Alt+F11,打开VBA编程界面
2、在VBA编程界面的工具栏,第二个按钮拉下来选模块
3、在左边栏的你需要计时器的那个工作表名字上双击,打开右边的程序书写区域
4、把下面的程序代码粘贴进去
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B1")) Is Nothing) Then
[B1] = "开始时间"
[C1] = Format(Now(), "Hh:mm:Ss")
[D1] = Timer
[D1].Font.ColorIndex = 2
[B2:D3].ClearContents
End If
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B2")) Is Nothing) Then
[B2] = "结束时间"
[C2] = Format(Now(), "Hh:mm:Ss")
[D2] = Timer
[D2].Font.ColorIndex = 2
[B3] = "总共用时"
[C3] = Format([D2] - [D1], "#0.00")
[D3] = "秒"
End If
Target.Offset(1, 0).Select
End Sub
5、关闭VBA编程界面回到工作表
6、双击B1开始计时,双击B2终止计时,用时结果在C3单元格
(特别提醒:要在Exce中通过菜单“工具-宏-安全性”把宏的安全级别设为中或低以允许宏的运行,否则宏不能运行也得不到你要的结果)
热心网友
时间:2023-10-24 01:56
需要用到VBA编程,以下是前人的留贴,供参考
操作步骤:
1、在Excel工作表里按Alt+F11,打开VBA编程界面
2、在VBA编程界面的工具栏,第二个按钮拉下来选模块
3、在左边栏的你需要计时器的那个工作表名字上双击,打开右边的程序书写区域
4、把下面的程序代码粘贴进去
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B1")) Is Nothing) Then
[B1] = "开始时间"
[C1] = Format(Now(), "Hh:mm:Ss")
[D1] = Timer
[D1].Font.ColorIndex = 2
[B2:D3].ClearContents
End If
If Target.Cells.Count = 1 And (Not Intersect(Target.Cells(1), Range("B2")) Is Nothing) Then
[B2] = "结束时间"
[C2] = Format(Now(), "Hh:mm:Ss")
[D2] = Timer
[D2].Font.ColorIndex = 2
[B3] = "总共用时"
[C3] = Format([D2] - [D1], "#0.00")
[D3] = "秒"
End If
Target.Offset(1, 0).Select
End Sub
5、关闭VBA编程界面回到工作表
6、双击B1开始计时,双击B2终止计时,用时结果在C3单元格
(特别提醒:要在Exce中通过菜单“工具-宏-安全性”把宏的安全级别设为中或低以允许宏的运行,否则宏不能运行也得不到你要的结果)