+ Reply to Thread
Results 1 to 3 of 3

VLookup Excel table to populate combobox in userform

  1. #1
    Registered User
    Join Date
    01-23-2013
    Location
    Pittsburgh
    MS-Off Ver
    Excel 2010
    Posts
    8

    VLookup Excel table to populate combobox in userform

    I have a userform and have comboboxes for station # and station name. Each # has a unique name and vice versa. I would like the user to be able to either select the station # and have the corresponding station name populate in the combobox or the other way around.

    I tried a VLookup of the table in my code, but I can't get it to work. I get a type mismatch error.
    Here is the code for changing the station #:

    Private Sub cboStationNum_Change()
    cboStationName.RowSource = Application.VLookup(cboStationNum.Value, ATLCTable, 2)
    End Sub

    I'd like to know what I'm doing wrong with the VLookup and if you have any better suggestions on how to get the same functionality that's fine too.

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Use the list index of the listbox to find the row the selected station # is from.

    With that you can get the station name.

    That should be straightforward.

    If you have trouble post back and attach a sample workbook.
    Last edited by Norie; 02-14-2013 at 01:05 PM.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-23-2013
    Location
    Pittsburgh
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VLookup Excel table to populate combobox in userform

    Thanks ... I'm not really familiar with that though. Here is how my named range and userform look:

    Capture2.PNG

    Station # Name
    18 PITT
    19 GRBG
    25 DUBO
    35 OILC
    63 ALTO
    84 HRBG
    111 HRBL
    200 WMPT
    366 PTSV
    401 PHIL

    I want my combobox to automatically find the corresponding # or name depending on what the user selects while in the userform

+ 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