+ Reply to Thread
Results 1 to 3 of 3

Help with creating a UDF

  1. #1
    Registered User
    Join Date
    04-03-2005
    Posts
    4

    Help with creating a UDF

    Good day:

    I'm trying to create my first UDF to replace some formulas that are 500+ characters long. The objective is to use Vlookup to find a value in one table, do some arithmetic on that value, look up another value in another table and do some arithmetic on it, then do some more arithmetic on the results of those and give a result.

    Start small and learn: created a table A1:B10 named test1 with 1 to 10 in Col A then 10 to 100 in increments of 10 in Col B. In Cell A13 is the value I want to look up (i.e <3>)with the UDF in Cell B13 =TestUDF(A13) expecting a result of <30>.

    I am getting the error #VALUE.


    Function TestUDF(Lookup As Integer) As Integer
    TestUDF = Application.WorksheetFunction.VLookup(Lookup, test1, 2)

    End Function

    Any insights?

    Thanks,
    Rod

  2. #2
    Forum Expert
    Join Date
    12-24-2004
    Location
    Sweden
    Posts
    1,256
    This example might help:

    Option Explicit
    ' Example =LOOKUPV (E1, A1:C10, 2, FALSE, "")
    Function LOOKUPV(Lookup_Value, Table_Array As Range, Col_Index_Num, Range_value, Optional Error_Msg)
    LOOKUPV = Application.VLookup(Lookup_Value, Table_Array, Col_Index_Num, Range_value)
    If IsError(LOOKUPV) And Not IsMissing(Error_Msg) Then LOOKUPV = Error_Msg
    End Function

    Should be 6 rows


    Ola Sandström

  3. #3
    Registered User
    Join Date
    04-03-2005
    Posts
    4
    Ola:

    It's like magic...works like a hot damn! Thank you.

    Now I'll apply this to successfully more complicated scenarios until I get to the specific obstacle that I want to overcome.

    Rod

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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