Thread
:
Here's how to require user to pass a particular param type to a cellfunction (intercepting #VALUE).
View Single Post
#
2
Posted to microsoft.public.excel.programming
Dave Peterson
external usenet poster
Posts: 35,218
Here's how to require user to pass a particular param type to a cellfunction (intercepting #VALUE).
This worked fine for me:
Option Explicit
Function Plural(ByVal S As String) As String
Plural = S & "s"
End Function
It worked with:
=plural(a1)
and
=plural("asdf")
Maybe it was something else that was causing the trouble. (or maybe you used
something materially wrong in the function declaration????
wrote:
I want to share something that took me some hrs. to learn, to possibly
spare others my pain.
I wrote a function the user can use in a cell, e.g.:
public function Plural(ByVal S as <immaterial here) as string
Plural = S & "s"
end function
But I can only handle an address or range name, not a literal string,
i.e.:
=Plural($A$1) not =Plural("apple")
I think I've found the solution by making the param a Variant and
using TypeName:
public function Plural(ByVal S as Variant) as string
if TypeName(S) = "Range" then
Plural = W & "s"
else
Plural = "Paisan, you sick in da head? Use a range, not a literal
string."
endif
end function
***
Pa(ren)thetically, what the hell is with VarType?
When TypeName is "Range", it's 8. But when it's "String", it's ... 8.
I mean, Douglas Adams's 42 would be more informative.
***
--
Dave Peterson
Reply With Quote
Dave Peterson
View Public Profile
Find all posts by Dave Peterson