View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Zack Barresse[_3_] Zack Barresse[_3_] is offline
external usenet poster
 
Posts: 101
Default Pass function as argument to UDF

If you have the value in a cell, you can just refer to the cell. There is a
difference between what a VBA function can receive for text length and what
you can put in a cell. Do a search on Excel's cell length limitations for
more information.

As an example, I can use the Rept function in a cell and have it's cell
length 32,767 characters long. I then use your UDF to point to that cell
"=MyUDF(A1)" and I get the same value, non-errored.

HTH

--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)
To email, remove the NO SPAM. Please keep correspondence to the board, as
to benefit others.



"Ron Rosenfeld" wrote in message
...
On Wed, 08 Feb 2006 16:33:58 -0500, Ron Rosenfeld

wrote:

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