Using UDF on multiple sheets causes #NAME? error

VfTom

New Member
Joined
Mar 3, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi, I need some help with the following.
I have two workbooks where I need to do a lookup in between and obtain a value.
To be more precise there is one active mastersheet which contains all the data, and a map with separate sheets, and each sheet does a lookup on the mastersheet and obtain a specific value.

The lookup is done on multiple conditions.
The lookup value from the separate sheet is checked on the first column for the name, rest of the columns for the price, and color (only yellow marked items should be considered).

I also haved a third workbook where I have placed the whole code and the UDF.

This UDF works great within one workbook.
But in this setting with 3 workbooks I receive a #NAME? error. And this is what I need some help with.

I did a small research on this and I found there are solutions for this like:
- save the UDF in a personal.xls file, xla file or qualify the call with: =[Your Workbook.xls]MyFunct(Arg1, Arg2)


I've tried to place the UDF in a personal.xls file but that didn't work either
Is there an another way?
Thank you in advance for looking into it.

Here below an examle one of the separate sheets :

fruits.xlsx
ABC
1Company
24Fruits
3
4FruitPrice
5Red Apple#NAME?
6Green Apple#NAME?
7
partner
Cell Formulas
RangeFormula
B5:B6B5=GET_PRICE([fruits_source.xlsm]prices!$A$1:$D$7,$A$1,A5)


Here below an example of the master sheet:

fruits_source.xlsm
ABCDE
1PartnerGoldenRed AppleGreen Apple
2FruitsRUs€ 1€ 1€ 1
3
44Fruitsn/a€ 1€ 3
5
6OneADay€ 1n/an/a
7
8
prices


And here below the UDF:

Public Function GET_PRICE(ByVal RngPrices As Range, ByVal vPartner As String, vType As String) As Variant Dim vRow As Long Dim vColumn As Long With Application.WorksheetFunction vRow = .Match(vPartner, RngPrices.Columns(1), 0) vColumn = .Match(vType, RngPrices.Rows(1), 0) End With 'check color If RngPrices.Cells(vRow, vColumn).Interior.Color = vbYellow Then GET_PRICE = RngPrices.Cells(vRow, vColumn).Value Else 'not yellow, return N/A GET_PRICE = "Nope" End If End Function
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
If the UDF is in your personal macro workbook, you need to qualify the call with the name of the workbook - eg =Personal.xlsb!GET_PRICE([fruits_source.xlsm]prices!$A$1:$D$7,$A$1,A5)

Bear in mind that that UDF will not work if the source workbook is closed.
 
Upvote 1
I recommend saving your UDF in an addin since once you have set it up and activated it, it is very easy to keep adding new functions to the addin , so I find I am writing new functions all the time , I just save them in the addin just in case I want to use somewhere else. You can then call them in any workbok just like an excel function
 
Upvote 1
If the UDF is in your personal macro workbook, you need to qualify the call with the name of the workbook - eg =Personal.xlsb!GET_PRICE([fruits_source.xlsm]prices!$A$1:$D$7,$A$1,A5)

Bear in mind that that UDF will not work if the source workbook is closed.
thank you RoryA , something changed but now I get a #VALUE! error, any idea what that can be?
 
Upvote 0
I recommend saving your UDF in an addin since once you have set it up and activated it, it is very easy to keep adding new functions to the addin , so I find I am writing new functions all the time , I just save them in the addin just in case I want to use somewhere else. You can then call them in any workbok just like an excel function
thank you offthelip, the code should also be used by other users who don't have this plugin installed.
 
Upvote 0
thank you offthelip, the code should also be used by other users who don't have this plugin installed.
If other users need to use the function you can't put it in your personal.xlb either, the only way is to include in every workbook you send them . Alternatively you can get your users to install the addin themselves, I do have some clients that have done exactly that with my addin with UDF becausethey have found them useful
 
Upvote 0
If other users need to use the function you can't put it in your personal.xlb either, the only way is to include in every workbook you send them . Alternatively you can get your users to install the addin themselves, I do have some clients that have done exactly that with my addin with UDF becausethey have found them useful
you're right, I want to place the UDF in a third sheet where also the rest of the code is and can be used by others, but I'm sure these users will not download any addin's ...
 
Upvote 0

Forum statistics

Threads
1,215,849
Messages
6,127,276
Members
449,372
Latest member
charlottedv

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