How would I pass a function as an argument to a UDF?
For example:
=MyUDF(arg1, arg2, arg3)
where arg1 might be a literal text string, a reference to a cell containing a
string, OR a formula that returns a string:
SUBSTITUTE(A1,old_text,new_text)
I want to manipulate the resultant string in my UDF.
Thanks.
--ron
Thanks for all of your responses.
I did think it should work, and, with your postings indicating that it should
work, I've narrowed down the problem a bit further.
To simplify:
================
Function MyUDF(str)
MyUDF = str
End Function
================
=MyUDF((SUBSTITUTE(A6,"-","",1))
Initially it seemed that if the length of the string being generated by the
SUBSTITUTE worksheet function is greater than 255, an error is generated.
With the function as written, a #VALUE! error is returned and a breakpoint at
the 2nd line does not "break" the routine.
On closer examination, it appears that a further requirement has to do with the
manner of generating the long string. If the long string is generated by
various functions or operations (e.g. =REPT("This is a long string. ",30)),
then MyUDF will --> #VALUE!
However, if the one merely types in more than 255 characters, then the function
works OK.
The function will also work OK, regardless of how the long string is generated,
if one limits the string being generated by the SUBSTITUTE function to 255.
e.g.
A6: =REPT("-",300)
=myudf(SUBSTITUTE(A6,"-","",1)) --> #VALUE!
=myudf(SUBSTITUTE(LEFT(A6,257),"-","",1)) --> #VALUE!
=myudf(SUBSTITUTE(LEFT(A6,256),"-","",1)) --> a string of 255 hyphens
Any comments would be appreciated. In a limited search, I did not find
documentation of this "feature".
--ron