+ Reply to Thread
Results 1 to 2 of 2

[Help Needed] Custom Lookup Function

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2005
    Posts
    1

    [Help Needed] Custom Lookup Function

    Hello

    I'm writing a custom lookup function to deal with certain requirement. This is my use case.

    I've an Excel Workbook with multiple sheets. First Sheet is the "Master Data". In one of the other sheets I've a value which I want to look up in "Master Data" sheet and get the row number. Simple.

    I've written this function

    Function foo(lookup As Range)
    Dim foundCell As Range
    
    With Sheets("Master Data").UsedRange
        Set foundCell = .Find(lookup.Value)
        If Not foundCell Is Nothing Then
            foo = foundCell.Address
        Else
            foo = " :( "
        End If
    End With
    
    End Function
    But for some reason my function always returns , meaning it didn't find the value in the "Master Data" sheet. I'm pretty sure it is there.

    Same Function when converted to SUB and with hard coded lookup value returns correctly.

    Please help me out... what am I missing???

  2. #2
    Dave Peterson
    Guest

    Re: [Help Needed] Custom Lookup Function

    When you do a find (either manually or via code), excel remembers the last
    settings (part vs whole, matchcase, all that stuff).

    You might have better luck if you specify all the settings you want in your
    ..find statement.

    "rmsh76@gmail.co" wrote:
    >
    > Hello
    >
    > I'm writing a custom lookup function to deal with certain requirement.
    > This is my use case.
    >
    > I've an Excel Workbook with multiple sheets. First Sheet is the "Master
    > Data". In one of the other sheets I've a value which I want to look up
    > in "Master Data" sheet and get the row number. Simple.
    >
    > I've written this function
    >
    > Code:
    > --------------------
    >
    > Function foo(lookup As Range)
    > Dim foundCell As Range
    >
    > With Sheets("Master Data").UsedRange
    > Set foundCell = .Find(lookup.Value)
    > If Not foundCell Is Nothing Then
    > foo = foundCell.Address
    > Else
    > foo = " "
    > End If
    > End With
    >
    > End Function
    >
    > --------------------
    >
    > But for some reason my function always returns , meaning it didn't
    > find the value in the "Master Data" sheet. I'm pretty sure it is
    > there.
    >
    > Same Function when converted to SUB and with hard coded lookup value
    > returns correctly.
    >
    > Please help me out... what am I missing???
    >
    > --
    > rmsh76@gmail.co
    > ------------------------------------------------------------------------
    > rmsh76@gmail.co's Profile: http://www.excelforum.com/member.php...o&userid=26151
    > View this thread: http://www.excelforum.com/showthread...hreadid=394788


    --

    Dave Peterson

+ 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