how to make self-made vba function easily understood.

  • Thread starter Thread starter youngman
  • Start date Start date
Y

youngman

hi,

i am making some funcyions in excel vba ,when the fun is complicated it is
diffcult to recognize the meaning when i use the function.


for instance
Function CalculateSquareRoot(NumberArg As Double) As Double
If NumberArg < 0 Then
Exit Function '
Else
CalculateSquareRoot = Sqr(NumberArg)
End If
End Function

i mean how to make the meaning of NumberArg be easily recognized.
how to make a hint about the fun.

thank you
 
Someone has found a way of putting a helpfull paragraph
in the function wizard dialog box.

Open vba development window, place cursor inside your
UDF, press F2. This opens the object explorer.

Select your project from the list of libraries, right
click on your UDF (in the RH pane) and select properties.
Type your paragraph here.
 
Just to clarify Bruce's statement in contrast to my advice: That puts in a
description of the function, but not text for the arugments (the question
asked as I understood it).
 
thank you very much.

i am sorry i failed to save the property.
anything wrong with excel.
regards
 
I know this is a tacky way to do it, but you could add two arguments.
The first is a string (perhaps "DocumentationComment") and the second
is a Boolean.

The first is ignored, the second, if true, causes the function to
raise a Message Box with whatever comments you would like to see.

So, an example might be that you wrote the following into a cell:

=CalculateSquareRoot(4,"Set the following value to true if you want to
see a message regarding how this function works.",false)

for the following function:

CalculateSquareRoot(NumberArg As Double, DocumentationComment as
string,RaiseMessage as Boolean)

Function CalculateSquareRoot(NumberArg As Double, DocumentationComment
as string,RaiseMessage as Boolean) As Double
' Note that DocumentationComment is ignored
If RaiseMessage = True then
Msgbox "This function is used to determine the square root of a
number."
endif
If NumberArg < 0 Then
Exit Function '
Else
CalculateSquareRoot = Sqr(NumberArg)
End If
End Function

I know, tacky.

mike
 
Back
Top