Question : Without vb, does excel have a COALESCE or (or IFNULL, or VALUE) function? VALUE(p1,p2,p3….) returns first nonempty parameter
I get tired of using workarounds to do this function.
A simple example: column A should show contents of col c, except empty cells would have the word “–emtpy–“.
Sure, I can work around it with if(c5=””,”–empty–“,c5) , or with a custom format.
But, I often would prefer to say =VALUE(C5,”–empty–“)
I’ve even written a vba function called MY1stVALUE that does this but it slows things down quite a bit. (on the other hand, it gives me flexibility, because I can have varations like MY1stNUMBER and MY1stNONBLANK and MY1stALPHA.)
Solution : Without vb, does excel have a COALESCE or (or IFNULL, or VALUE) function?  VALUE(p1,p2,p3….) returns first nonempty parameter
To benchmark a worksheet function, you should enter the worksheet function in some cells (say A1:A10000) and run something like:
Sub testSpeed()
Dim t1 As Double, t2 As Double
t1 = Timer
Range("a1:a10000").Calculate
t2 = Timer
MsgBox t2 – t1
End Sub
instead of looping and calling the function from vba.
Now concerning your vba ParamArray function :
Public Function My1stValue(ParamArray params())
Dim i As Long
For i = 0 To UBound(params)
If Len(params(i) & "") > 0 Then
My1stValue = params(i)
Exit Function
End If
Next
My1stValue = ""
End Function
I checked the speed for both functions by entering them in A1:A10000 (each in a separate sheet), the runned times are between 1 and 2 seconds for both of them.
I guess there is no point in using an XLM macro in this case. Better sticking with VBA.
(but XLM macro should be faster in general when used as worksheet function, not in vba, … just to keep in mind)
Note: to run a XLM macro from vba , use the ExecuteExcel4Macro method.