Calling a User Defined Function (UDF) from a macro

Paul_Godley

New Member
Joined
Sep 5, 2002
Messages
18
I have written a UDf and saved it as an add-in. I can use this from any cell in any sheet and book.
I want to call the UDF from a macro, but cannot figure out how!
Can anybody help please?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Paul,

Welcome to the board!

Function have to be used like:

x = MyUDF(value)

Hope this helps!
 
Upvote 0
If you want to call it just like it is, you should use the syntax in Test, if you set a reference to the AddIn, you can use the syntax from Test2

<pre>Sub Test()
Dim a
a = Application.Run("MyAddin.xla!MyUDF", 1, 2)
End Sub

Sub Test2()
Dim a
a = MyAddin.MyUDF(1, 2)
End Sub</pre>
 
Upvote 0
Thanks Jim, that was quicker than i expected.

This works fine if the function is in the same book as the calling macro, but not if it's in a different workbook.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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