Custom Functions

djt76010

Board Regular
Joined
Feb 23, 2007
Messages
109
I am writing some custom functions to be saved in an Add-In file, but am having trouble saving named ranges. I would like named ranges in the Add-In file to be available in other spreadsheets. Is there a way to do this? Or is there a way to take a range from Excel and save it into a globally available named range using VBA?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What kind of range are you naming that you'd use in workbooks that don't yet exist?

Seems a bit unusual.

Alex.
 
Upvote 0
There are a number of age based tables that contain values for each age. We need to be able to pass in the name of the table into a custom built function that will be saved as an Add-In. Is this possible?
 
Upvote 0
If the function and the named range are both in the add-in then there's no need to pass the range as an argument to the function unless I missed something?
 
Upvote 0
I tried just having the named range in the Add-In file, but then the range is not available globally (in other workbooks).
 
Upvote 0
But it is available to the functions in the add-in, which is where I thought you needed access to it?
 
Upvote 0
I'm not sure I am explaining this properly . . . let me try again.

In my Add-In file I am writing custom functions ("MyFunction") and there are named ranges ("Table1", "Table2", . . . ). Once I add the Add-In to Excel, I would like to be able to open any spreadsheet and have =MyFunction(Age, "Table1") access the correct value from "Table1", but it doesn't work. I would like to somehow make "Table1" available to all spreadsheets that I open.

Thanks for the responses
 
Upvote 0
If Table1 is a range in the addin, you might write a UDF that returns the range of Table1.

Code:
Function Table1Range() as Range
    Set Table1Range = Range("Table1")
Exit Function

Table1Range() can be used by any workbook.
 
Upvote 0
Code:
Sub MyFunction(lngAge as Long, strTableName as string)
Dim rngTable as Range
' Get table from the add-in workbook
Set rngTable = ThisWorkbook.Names(strtablename).RefersToRange
' do whateve you need
'....
End Function
is the sort of thing I meant.
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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