使用macros计算Excel工作表中的已用时间

我的Excel表格如下所示:

阿———————乙———————Ç
银泰—————- Outtime ————— Elapsedtime
10:00 AM – – – – – – –
11:00 AM – – – – – – –
9:00 AM

我只想在列B上input数据时才计算列C,这应该使用macros….

请帮我解决这个….

Private Sub Worksheet_Change(ByVal Target As Excel.Range) 'when entering data in a cell in Col B On Error GoTo enditall Application.EnableEvents = False If Target.Cells.Column = 2 Then n = Target.Row If Me.Range("B" & n).Value <> "" Then Me.Range("C" & n).Value = Format(Me.Range("B" & n).Value - Me.Range("A" & n).Value, "hh:mm:ss") End If End If enditall: Application.EnableEvents = True End Sub 

右键单击工作表选项卡和“查看代码”。

将代码粘贴到该表单模块中。

Alt + q返回到Excel窗口。