D
DeDBlanK
Hello,
First off, thanks to those who help!
I am trying to write a UDF (for the first time) to combined these
formulas, at the bottom, that I have used in my worksheet to clean it
up and simplify it a bit. I am having troble in the code to get the
value to format to do what I want. If there is an easier way, please
let me know. Again, Thanks!
**************************************CODE
START***************************
Option Explicit
Public Function hmsDiff(sTime As Integer, fTime As Integer)
Dim BT As Long
Dim ET As Long
If sTime <> "" Then
If Len(sTime) > 5 Then
BT = TimeValue(Format(Left(sTime, 2) & Left(Right(sTime,
4), 2) & Right(sTime, 2), "0\:00\:00"))
Else
BT = TimeValue(Format(Left(sTime, 1) & Left(Right(sTime,
4), 2) & Right(sTime, 2), "00\:00\:00"))
End If
End If
If fTime <> "" Then
If Len(fTime) > 5 Then
ET = TimeValue(Format(Left(fTime, 2) & Left(Right(fTime,
4), 2) & Right(fTime, 2), "0\:00\:00"))
Else
ET = TimeValue(Format(Left(fTime, 1) & Left(Right(fTime,
4), 2) & Right(fTime, 2), "00\:00\:00"))
End If
End If
If IsNull(sTime) Then
If IsNull(fTime) Then
hmsDiff = ""
Else
If sTime > fTime Then
hmsDiff = 1440 * (ET Mod 1) - 1400 * (BT Mod 1) + 720
Else
hmsDiff = 1440 * (ET Mod 1) - 1400 * (BT Mod 1)
End If
End If
End If
End Function
**************************************CODE
END***************************
WORKSHEET FORMULAS
CELL I6
63000
CELL J6
74500
CELL CJ5
=IF(I6="","",IF(LEN(I6)>5,TIMEVALUE(TEXT(LEFT(I6,2)&LEFT(RIGHT(I6,4),2)
&RIGHT(I6,2),"0\:00\:00")),TIMEVALUE(TEXT(LEFT(I6,1)&LEFT(RIGHT(I6,4),
2)&RIGHT(I6,2),"00\:00\:00"))))
CELL CK5
=IF(J6="","",IF(LEN(J6)>5,TIMEVALUE(TEXT(LEFT(J6,2)&LEFT(RIGHT(J6,4),2)
&RIGHT(J6,2),"0\:00\:00")),TIMEVALUE(TEXT(LEFT(J6,1)&LEFT(RIGHT(J6,4),
2)&RIGHT(J6,2),"00\:00\:00"))))
CELL CQ5
=IF(I6="",0,IF(I6>J6,1440*MOD(CK5,1)-1440*MOD(CJ5,1)+720,1440*MOD
(CK5,1)-1440*MOD(CJ5,1)))
First off, thanks to those who help!
I am trying to write a UDF (for the first time) to combined these
formulas, at the bottom, that I have used in my worksheet to clean it
up and simplify it a bit. I am having troble in the code to get the
value to format to do what I want. If there is an easier way, please
let me know. Again, Thanks!
**************************************CODE
START***************************
Option Explicit
Public Function hmsDiff(sTime As Integer, fTime As Integer)
Dim BT As Long
Dim ET As Long
If sTime <> "" Then
If Len(sTime) > 5 Then
BT = TimeValue(Format(Left(sTime, 2) & Left(Right(sTime,
4), 2) & Right(sTime, 2), "0\:00\:00"))
Else
BT = TimeValue(Format(Left(sTime, 1) & Left(Right(sTime,
4), 2) & Right(sTime, 2), "00\:00\:00"))
End If
End If
If fTime <> "" Then
If Len(fTime) > 5 Then
ET = TimeValue(Format(Left(fTime, 2) & Left(Right(fTime,
4), 2) & Right(fTime, 2), "0\:00\:00"))
Else
ET = TimeValue(Format(Left(fTime, 1) & Left(Right(fTime,
4), 2) & Right(fTime, 2), "00\:00\:00"))
End If
End If
If IsNull(sTime) Then
If IsNull(fTime) Then
hmsDiff = ""
Else
If sTime > fTime Then
hmsDiff = 1440 * (ET Mod 1) - 1400 * (BT Mod 1) + 720
Else
hmsDiff = 1440 * (ET Mod 1) - 1400 * (BT Mod 1)
End If
End If
End If
End Function
**************************************CODE
END***************************
WORKSHEET FORMULAS
CELL I6
63000
CELL J6
74500
CELL CJ5
=IF(I6="","",IF(LEN(I6)>5,TIMEVALUE(TEXT(LEFT(I6,2)&LEFT(RIGHT(I6,4),2)
&RIGHT(I6,2),"0\:00\:00")),TIMEVALUE(TEXT(LEFT(I6,1)&LEFT(RIGHT(I6,4),
2)&RIGHT(I6,2),"00\:00\:00"))))
CELL CK5
=IF(J6="","",IF(LEN(J6)>5,TIMEVALUE(TEXT(LEFT(J6,2)&LEFT(RIGHT(J6,4),2)
&RIGHT(J6,2),"0\:00\:00")),TIMEVALUE(TEXT(LEFT(J6,1)&LEFT(RIGHT(J6,4),
2)&RIGHT(J6,2),"00\:00\:00"))))
CELL CQ5
=IF(I6="",0,IF(I6>J6,1440*MOD(CK5,1)-1440*MOD(CJ5,1)+720,1440*MOD
(CK5,1)-1440*MOD(CJ5,1)))