+ Reply to Thread
Results 1 to 6 of 6

combobox vlookup

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    combobox vlookup

    Hello I am trying to get vba to vlookup a value from a combobox and return a value from the data sheet. My code so far is:

    Private Sub TextBox1_Change()
    Me.TextBox1.Value = Application.WorksheetFunction.VLookup(Me.ComboBox2.Value, "a2:ao10000", 41, 1, True)
    End Sub

    I am trying to look at the value in combobox2 and return the relevant data from that row in the data sheet in textbox1. A2:AO10000 is my data sheet range, I am trying to return the data in textbox1 from column a.

    Any ideas?

    Thanks

    Zak

  2. #2
    Registered User
    Join Date
    09-10-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: combobox vlookup

    Not exactly what you are looking for, but might help

    http://www.youtube.com/watch?v=vkPoViUhkxU

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: combobox vlookup

    Hi,

    Try

    Me.TextBox1.Value = Application.WorksheetFunction.VLookup(Me.ComboBox2.Value, Range("a2:ao10000"), 41, 1, True)
    And if the table you're looking up is not on the active sheet you'll need to preface the Range() instruction with the Sheet name.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: combobox vlookup

    Hi,

    There are several errors in your code :
    - Your vlookup() function takes 5 arguments while maximum arguments for vlookup() is 4, look here : here
    - As pointed by Richard, you must pass a range object in second argument, not a string
    - Since the trigger is when the combobox2 's value is changed, then you should put the code in ComboBox2_Change() event, not TextBox1_Change() event
    - You also must put an error trapper if the vlookup can't match any result (similiar to #N/A), otherwise the "“Unable to get the VLookup property of the WorksheetFunction Class” error will be raised. Look here for the solution : link
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: combobox vlookup

    @karedog,

    Good catch! I'd missed the 5 argument error completely. Well spotted.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: combobox vlookup

    Quote Originally Posted by Richard Buttrey View Post
    @karedog,

    Good catch! I'd missed the 5 argument error completely. Well spotted.
    It must be the power of the mighty Coffee

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. ComboBox + Vlookup ?
    By kilown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2014, 10:08 AM
  2. Vlookup and combobox issues
    By Charles1104 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2012, 12:02 PM
  3. VLookup and Combobox
    By G-Unit in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-30-2011, 07:51 PM
  4. [SOLVED] combobox with vlookup
    By soulfear in forum Excel General
    Replies: 0
    Last Post: 05-09-2006, 02:35 AM
  5. vlookup in combobox
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-01-2005, 08:45 PM

Tags for this Thread

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