+ Reply to Thread
Results 1 to 8 of 8

Lookup UDF

  1. #1
    Registered User
    Join Date
    09-23-2014
    Location
    Washington, DC
    MS-Off Ver
    2011
    Posts
    92

    Lookup UDF

    Hi All,

    Working on my first UDF and I'm getting a #VALUE! error.

    Attached is a sample file. Basically I'm trying to write a function to replace the INDEX/MATCH I have to write constantly. In the sample file, the lookup values are in a separate tab. For my purposes, the lookup values are in a separate workbook.

    Any help would be very much appreciated!

    Best,
    Alex
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Lookup UDF

    Does this work for you?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Lookup UDF

    The function will not recalculate if any changes are made on the Data sheet.

    You need to make it volatile, or pass the data sheet ranges as function arguments so that they are recognised as precedents to the function in order for it to calculate properly.

  4. #4
    Registered User
    Join Date
    09-23-2014
    Location
    Washington, DC
    MS-Off Ver
    2011
    Posts
    92

    Re: Lookup UDF

    Thanks for your replies. Davesexcel, that works in the sample file, but still returns an error when I try to add path and workbook names. Any thoughts on how I should fix that?

    Good call jason.b75

  5. #5
    Registered User
    Join Date
    09-23-2014
    Location
    Washington, DC
    MS-Off Ver
    2011
    Posts
    92

    Re: Lookup UDF

    Thanks for your replies. Davesexcel, that works in the sample file, but still returns an error when I try to add path and workbook names. Any thoughts on how I should fix that?

    Good call jason.b75

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Lookup UDF

    In the file in post #1, I see mostly typo errors:

    The file name is udflookuptext.xlsm, but your code is trying to search in a file named "udfloopuptest" (no extension).
    I notice that you are erroneously trying to access a worksheet object instead of the worksheets collection.

    When I correct those two errors (spell the file name correctly and include extension, access worksheets("data")), the code seems to execute correctly.

    You mention giving the function a path. I don't know that path has any meaning for an opened workbook, so I wonder if you are trying to access closed workbooks with this udf. I don't know that VBA can do that (though if others know better, feel free to correct me). If you are needing to access data in closed workbooks, I would make that point clear here in the thread, so that that aspect of the task can be properly accounted for in any proposed solutions.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Lookup UDF

    Why not skip the UDF idea, if you want to reduce typing, use some named range trickery instead.

    * Note that I haven't tried this with the Data sheet in a separate, closed workbook, hopefully it will work *

    Create a named range called GetMSA_County that refers to

    =INDEX(Data!$D$2:$D$12,MATCH('Front End'!$A:$A,Data!$B$2:$B$12,0))

    Remember to include the full path for the other workbook that holds the Data sheet.

    Now just enter =GetMSA_County into B2 of the front end sheet and the background named range formula will (hopefully) do the rest for you.

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Lookup UDF

    The function appears to work like this

    Please Login or Register  to view this content.
    The function probably will only work if the other workbook is open.
    Formulas will work if the other workbook is closed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Two Lookup and Return (Lookup the column, then lookup the row)
    By Branbran10 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-05-2015, 04:55 PM
  2. Replies: 4
    Last Post: 05-19-2015, 08:42 PM
  3. Replies: 3
    Last Post: 04-08-2014, 03:11 AM
  4. Replies: 2
    Last Post: 05-19-2013, 08:46 AM
  5. Replies: 1
    Last Post: 11-07-2012, 01:57 PM
  6. Search lookup array to find lookup value contained within text string
    By Cookstein2 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2011, 09:42 AM
  7. Replies: 7
    Last Post: 06-19-2011, 12:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1