+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25

Thread: customLookup Function (2)

  1. #16
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    Ok, your's work fine I agree, but what happens when you have your validation selection and index on a different page to the one containing the actual tables...? See my attached file
    Attached Files Attached Files
    Jacques


  2. #17
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: customLookup Function (2)

    I think you will need to re-write your function to allow that as Cells(myRow, myCol).Value will always be looking on the worksheet that invoked the function for the result.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #18
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    Hi Dom,

    My problem comes in when you have the validation selection and index on a seperate sheet from the table with the values.

    See attached...
    Attached Files Attached Files
    Jacques


  4. #19
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: customLookup Function (2)

    What I said above.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  5. #20
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    Sorry, it didnt look like my post was actually posted, will read and reply thanks
    Jacques


  6. #21
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    But the range that I specify refers to the appropriate sheet, how will this make a difference?
    Jacques


  7. #22
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: customLookup Function (2)

    You only specify the ranges for the values that you are trying to match, not the range of the table that holds the data that you are wanting to return the value from. The function is assuming that this is on the worksheet you are invoking the function from.

    I'd have a go at re-writing it but I'm really busy today I'm afraid.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  8. #23
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    I understand the problem.

    Is re-wirting this something that I can pick up off the net, or is it something you have come up with on your own?
    Jacques


  9. #24
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: customLookup Function (2)

    You could alter the code to this:
    Option Explicit
    Function myLookup_Index2(rowValue As String, rowRng As Range, colValue As String, _
        colRng As Range, rngTable As Range) As Double
    'Find the intersection between two ranges: Row vs Column refering to two specific values
    
    
        Dim myRow As Long, myCol As Long
    
        On Error GoTo err_handler
        myRow = Application.WorksheetFunction.Match(rowValue, rowRng, 0)
        myCol = Application.WorksheetFunction.Match(colValue, colRng, 0)
        myLookup_Index2 = rngTable.Cells(myRow, myCol).Value
        Exit Function
        
    err_handler:
        myLookup_Index2 = CVErr(xlErrRef)
    End Function
    and then call it using:
    =myLookup_Index2(B2,'Lookup Sheet'!B4:B8,B3,'Lookup Sheet'!C3:G3,'Lookup Sheet'!C4:G8)

    Note the additional table argument at the end, and the fact that the function does not need to be volatile anymore.

  10. #25
    Valued Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: customLookup Function (2)

    Thanks Romper, works like a charm.

    Dom, thanks for the help.
    Jacques


+ 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.2.0