write help for a UDF

gavinkelly

Board Regular
Joined
Jan 12, 2008
Messages
220
how do i write "help" for a user defined function which can be viewed in the "insert function" tab.

Also why do the arguments not show when i begin to write =UDF(... ) unlike a none user defined fuction i.e. the fuctions already in excel? (UDF is the name i have called my user defined funtion?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I'm not sure if you can get the tooltips up for a UDF, so this isn't exactly the answer you're looking for... but, if your UDF is:

Code:
function my_UDF(var1 as double, var2 as double) as double
my_UDF = var1 * var2
end function

and you type =my_UDF( in a cell and press CTRL+SHIFT+A, you'll see the arguments shown (or, CTRL+A will bring up the dialog box).
 
Upvote 0
ok but also:
i have declared an optional argument but how do i set a default value if the user does not enter the argument?
 
Upvote 0
Can you post the UDF? I believe you can set the optional like this:

Optional Variable As Long = 1

Hope that helps.
 
Upvote 0
Function ContainsText2(Rng As Range, Phrase As String, Optional KeyWordPosition As Integer, Optional AssignedPosition As Integer) As String

ContainsText2 KeyWordPosition:="1" 'this is not working
ContainsText2 AssignedPosition:="2" 'this neither


n = 1
For x = 1 To Rng.Rows.Count
If 0 < InStr(Phrase, Rng(n, KeyWordPosition)) Then
ContainsText2 = Rng(n, AssignedPosition)
Exit For
End If
n = n + 1
Next x

End Function
 
Upvote 0
Can you do something like:

Code:
Function ContainsText2(Rng As Range, Phrase As String, Optional KeyWordPosition As Integer=1, Optional AssignedPosition As Integer=1) As String
Or:

Code:
Function ContainsText2(Rng As Range, Phrase As String, Optional KeyWordPosition As Integer, Optional AssignedPosition As Integer) As String

 if KeyWordPosition= 0 then KeyWordPosition = 1
 if AssignedPosition =0 then AssignedPosition = 2

n = 1
For x = 1 To Rng.Rows.Count
If 0 < InStr(Phrase, Rng(n, KeyWordPosition)) Then
ContainsText2 = Rng(n, AssignedPosition)
Exit For
End If
n = n + 1
Next x

End Function
Preferrably I'd use the first approach. Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,669
Messages
6,120,828
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top