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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Jim North

MrExcel MVP
Joined
Jun 20, 2002
Messages
791
Hi Paul,

Welcome to the board!

Function have to be used like:

x = MyUDF(value)

Hope this helps!
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
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>
 

Paul_Godley

New Member
Joined
Sep 5, 2002
Messages
18
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,808
Members
416,884
Latest member
leeshjay

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
Top