Этот код из моего дополнения к 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 ButtonTCTC_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