我有大约140个单元格(它们在垂直列中),包含格式为hh:mm:ss:ff的时间码。每秒有24帧。我想添加它们,所以我有所有提取的总持续时间。任何人都可以告诉我如何在Micosoft Excel中做到这一点?非常感谢任何帮助,因为我真的很无能为力......非常感谢!
这段代码来自我的excel补充“TCCalculator”。计算器是免费的,但不是代码。如果主持人给我许可,我可以在此处添加指向我的Google云端硬盘的链接
你必须做三件事。
1- Create a Button to start the calculation (ButtonTC).
2- Create some VBA functions (I will show it to you)
3- Select a range and click on ButtonTC
通过这种方法,我们可以选择不同细胞的范围。这将是所有的总和。
您只需要这些功能:
Private Sub ButtonTC_Click
Private Sub ButtonTC_Click()
Dim framesRef As Double
‘framesRef can be 23.98, 24, 25, 29.97…
'Beware, the decimal point may vary depending on the system configuration
'The cell that will store the final result must be free of data. We can also get the result with a msgbox
Cells("1", "A") = f_CalculateRangeTC(framesRef)
End Sub
公共函数f_CalculateRangeTC
Public Function f_CalculateRangeTC(ByVal framesRef As Double) As String
Dim obj_Cell As Range
Dim sumaTotalFrames As Double
sumaTotalFrames = 0
For Each obj_Cell In Selection.Cells
With obj_Cell
sumaTotalFrames = sumaTotalFrames + f_CalculateTcInFrames(.Text, framesRef)
End With
Next
f_CalculateRangeTC = f_ConvertFramesTo_HHMMSSFF(sumaTotalFrames, framesRef)
End Function
公共函数f_CalculateTcInFrames
Public Function f_CalculateTcInFrames(ByVal numToConvert As String, ByVal framesRef As Double) As Double
Dim fra2f, seg2f, min2f, hor2f As Double
fra2f = 0
seg2f = 0
min2f = 0
hor2f = 0
‘This two sentences convert an unformated number to correct format 1:23:05 to 00012305
‘But this not work with this: 1:1:02 (1 minute, 1 second, 2 frames) becomes 00001102 ¡ERROR!
numToConvert = Replace(numToConvert, ":", "")
numToConvert = Right("00000000" & numToConvert, 8)
fra2f = Mid(numToConvert, 7, 2) 'Frames to frames
seg2f = Mid(numToConvert, 5, 2) * (framesRef) ‘Seconds to frames
min2f = Mid(numToConvert, 3, 2) * (60 * framesRef) ‘Minutes to frames
hor2f = Mid(numToConvert, 1, 2) * (3600 * framesRef) ‘Hours to frames
sumaFrames = hor2f + min2f + seg2f + fra2f
f_CalculateTcInFrames = sumaFrames 'Salimos de la función y devolvemos el valor.
Exit Function