我有大约 140 个单元格(它们位于垂直列中),其中包含格式为 hh:mm:ss:ff 的时间码。每秒有 24 帧。我想添加它们,所以我有所有提取的总持续时间。谁能告诉我如何在 Micosoft Excel 中做到这一点?非常感谢任何帮助,因为我真的一无所知......提前非常感谢!
问问题
2242 次
3 回答
0
这段代码来自我的 excel 补充“TCCalculator”。计算器是免费的,但不是代码。如果版主允许,我可以将我的 Google Drive 链接放在这里
你必须做三件事。
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
使用这种方法,我们可以选择不同单元格的范围。它将成为所有的总和。
您只需要这些功能:
私有子按钮TC_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
于 2019-04-09T20:48:32.443 回答