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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,955
Messages
5,834,573
Members
430,297
Latest member
xa_gta

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