Function SumarHoras(ByVal Hora1 As String, ByVal Hora2 As String) As String
Dim H_Hora1 As String
Dim H_Hora2 As String
Dim M_Hora1 As String
Dim M_Hora2 As String
Dim ST_Horas As Long
Dim ST_Minutos As Long
Dim Horas As Long
Dim Minutos As Long
Dim MinTemp As Long
Dim THoras As String
Dim TMinutos As String
Dim PosComa As Integer
Dim temp As Double
Dim SepDecimal As String * 1
'//Suma Horas
H_Hora1 = Left$(Hora1, (InStr(1, (Hora1), "h")) - 1)
H_Hora2 = Left$(Hora2, (InStr(1, (Hora2), "h")) - 1)
ST_Horas = Val(H_Hora1) + Val(H_Hora2)
'//Suma Minutos
PosComa = Val(InStr(1, (Hora1), ",")) + 1
M_Hora1 = Val(Mid$(Hora1, PosComa, Len(Hora1) - PosComa))
PosComa = Val(InStr(1, (Hora2), ",")) + 1
M_Hora2 = Val(Mid$(Hora2, PosComa, Len(Hora2) - PosComa))
ST_Minutos = Val(M_Hora1) + Val(M_Hora2)
MinTemp = (ST_Horas * 60) + ST_Minutos
temp = (1 / 2)
If InStr(1, temp, ",") <> 0 Then
SepDecimal = ","
End If
If InStr(1, temp, ".") <> 0 Then
SepDecimal = "."
End If
'Hora exacta (Si MinTemp es nº entero)
If InStr(1, (MinTemp / 60), SepDecimal) = 0 Then
Horas = (MinTemp / 60)
Minutos = 0
'Solo minutos (Si MinTemp < 60)
ElseIf MinTemp < 60 Then
Horas = 0
Minutos = MinTemp
Else
'Hora con minutos
Horas = Int(MinTemp / 60)
Minutos = MinTemp - (Horas * 60)
End If
THoras = Horas
If Len(THoras) = 1 Then
THoras = "0" & Horas
Else
THoras = Horas
End If
TMinutos = Minutos
If Len(TMinutos) = 1 Then
TMinutos = "0" & Minutos
Else
TMinutos = Minutos
End If
SumarHoras = THoras & "h, " & TMinutos & "m"
End Function