JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,676
- Office Version
- 365
- Platform
- Windows
Many years ago, I wrote my FmtTime UDF. Here's the function declaration statement:
Most of the calls calculate a difference between two date-time values and pass that to FmtTime. Here's an example:
I just encountered a situation where one of the date-time values is missing. This means that I have to test both values in the calling cell, which results in a horribly complex expression. I'd like to modify the UDF to accept both values. That way, the UDF can check both and values and return a result if both date-times are valid or an error if either one is not.
I know the way to handle this is to change the syntax to something like this:
The problem is that this UDF is called literally hundreds of times in dozens of workbooks. Manually updating them all would be a headache. As an alternative, is there a way to pass one or two numbers as the first parameter? None of these options work:
Thanks
VBA Code:
Public Function FmtTime(ByRef pTime As Double, _
Optional ByRef pDP As Long = 1, _
Optional ByRef pInUnits As String = "Secs", _
Optional ByRef pNegOK As Boolean = False _
) As String
Most of the calls calculate a difference between two date-time values and pass that to FmtTime. Here's an example:
Code:
=FmtTime(Endtime-Starttime)
I just encountered a situation where one of the date-time values is missing. This means that I have to test both values in the calling cell, which results in a horribly complex expression. I'd like to modify the UDF to accept both values. That way, the UDF can check both and values and return a result if both date-times are valid or an error if either one is not.
I know the way to handle this is to change the syntax to something like this:
VBA Code:
Public Function FmtTime(ByRef pStartTime As Double, ByRef pEndTime _
Optional ByRef pDP As Long = 1, _
Optional ByRef pInUnits As String = "Secs", _
Optional ByRef pNegOK As Boolean = False _
) As String
The problem is that this UDF is called literally hundreds of times in dozens of workbooks. Manually updating them all would be a headache. As an alternative, is there a way to pass one or two numbers as the first parameter? None of these options work:
Code:
=FmtTime(B7 C7)
=FmtTime((B7 C7))
=FmtTime((B7,C7))
Thanks