+ Reply to Thread
Results 1 to 12 of 12

application.vlookup

Hybrid View

  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    Guernsey
    MS-Off Ver
    Excel 2007
    Posts
    26

    application.vlookup

    I have a user form with a combo box of fund names (cmbFnd) and a text box assigned to the ISIN of that fund (txtISIN). the table holding fund names and ISINs is in a different workbook (S:\IAM Institutions\Institutional Master\Client - Product Matrix IB.xlsm) on the worksheet 'PerTrac Report', Range A6:B71 with A holding the Fund Name and B holding the ISIN and the column headings were in Row 3. When I select an entry from the combo box I would like it to lookup the respective ISIN from that other workbook and enter it into the text box. And I want it to do this without the other workbook being open. So far I get that i should probably be using application.vlookup but I've no idea about how it works.
    Any help would be so greatly appreciated
    Imi
    Oh, if it helps, this used to be a nice nonVBA form in the client-product matrix spreadsheet and the respective formula was:
    =VLOOKUP($D$17,'PerTrac Report'!$A$6:$K$71, MATCH("ISIN",'PerTrac Report'!$A$3:$K$3,0),FALSE)
    where D17 held the fund name
    Last edited by ImboJones; 08-20-2010 at 10:17 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: application.vlookup

    Hello,

    You're probably after

    Application.WorksheetFunction.Vlookup(lookup_value,lookup_range,column,exact)
    The syntax is the same as in the worksheet function, but you can pass the arguments as variables.

    cheers

  3. #3
    Registered User
    Join Date
    07-12-2010
    Location
    Guernsey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: application.vlookup

    thanks.
    though i'm still not entirely sure where I'm putting this in my code, or how to reference a different workbook.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,332

    Re: application.vlookup

    Quote Originally Posted by ImboJones View Post
    And I want it to do this without the other workbook being open.
    that won't work with worksheetfunction.vlookup

    You could use ADO to extract the data from the table, or you could enter the formula into a blank cell in a worksheet and then retrieve the value and delete the formula.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    07-12-2010
    Location
    Guernsey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: application.vlookup

    Does it make it easier if I then link the Pertrac Report to a hidden sheet in the workbook that holds my user form, effectively moving the table into the workbook (but so that it gets updated when the other workbook does.
    So now I want to look up the Fund name chosen in cmbFnd from the sheet PertracReport in the same workbook and enter the relevant ISIN into txtISIN.
    Is that possible?
    TIA

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: application.vlookup

    You can read the table in

    S:\IAM Institutions\Institutional Master\Client - Product Matrix IB.xlsm on the worksheet 'PerTrac Report', Range A6:B71 in one move into your combobox

    Private Userform_Initialize()
       with workbooks.add "S:\IAM Institutions\Institutional Master\Client - Product Matrix IB.xlsm "
          cmbFunds.list=.sheets("'PerTrac Report").range("A6:B71").value
         .close false
       end with
    End sub
    If you choose the fund's name in the combobox you can see the ISIN-code in textbox1 using

    Private sub cmbFunds_Change()
       if cmbFunds.listindex>-1 then teTxBox1.Text=cmbfunds.List(cmbFunds.Listindex,2)
    End Sub

  7. #7
    Registered User
    Join Date
    07-12-2010
    Location
    Guernsey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: application.vlookup

    It looks promising but I'm getting
    Run-time error '9':
    Subscript out of range.

    Any suggestions?
    Thanks

  8. #8
    Registered User
    Join Date
    07-12-2010
    Location
    Guernsey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: application.vlookup

    Ok I had a fiddle, but I'm still getting issues.
    currently it's;
       Private Sub UserForm_Initialize()
        With Workbooks.Add("S:\IAM Institutions\Institutional Master\Client - Product Matrix IB.xlsm")
             cmbFnd.List = .Sheets("PerTrac Report").Range("A6:B71").Value
         .Close False
       End With
    End Sub
    and then
    Private Sub cmbFnd_Change()
     If cmbFnd.ListIndex > -1 Then
     txtISIN.Value = cmbFnd.List(cmbFnd.ListIndex, 2)
     End If
    End Sub
    and it comes up with
    Run-time error '-2147024809 (80070057)';
    Could not get the list property. Invalid argument.
    I'm pretty certain it's something to do with the second bit because that happens after I've chosen from the combobox but I have no idea what's going on.
    thanks

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,332

    Re: application.vlookup

    Change:
    ("'PerTrac Report")
    to:
    ("PerTrac Report")

+ 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