+ Reply to Thread
Results 1 to 3 of 3

TextBox VLookup N00B

  1. #1
    Registered User
    Join Date
    06-14-2013
    Location
    San Jose, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question TextBox VLookup N00B

    Hi,

    I have a UserForm with. When One TextBox (TextBox2) is filled out, I want another TextBox (TextBox4) to autofill based on the results of a Vlookup. This is my first attempt at a "smarter" UserForm.

    In the UserForm(Code) window I changed the automatically generated control code for TextBox2 to the following:

    Please Login or Register  to view this content.
    What is kind of driving me nuts is: If I change the ,range_lookup to TRUE for "approximate match" the code returns a value from the Vlookup... It is the WRONG value but it returns and populates TextBox4. When the code is run as above I get: Run-time error '-2147352571(80020005)': Could not set the Value property. Type Mismatch.

    Being new to UserForms, and knowing that I can make code *like* this work on a sheet I have been frustrated. Current file contains confidential information so I have not posted it. Worksheets("VendorData") column A is a unique Number I am searching for, Column B is the vendor's name that I want returned. I suspect it has something to do with ..._Exit(ByVal Cancel As MSForms.ReturnBoolean) because I truly do NOT understand what that is doing, other than waiting until the user exits the TextBox before running the code.

    Thanks in advance.
    Last edited by mhowden42; 06-17-2013 at 03:40 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: TextBox VLookup N00B

    Textboxes contain text, so to do a lookup from the textbox value against a range with numbers you need to convert the text to a number.

    To do that you can use one of the various conversion functions, eg CDbl, CLng, Val etc

    Also, to avoid the type mismatch error you can check if the Vlookup has been succesful before trying to put a value in the other textbox.


    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-14-2013
    Location
    San Jose, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: TextBox VLookup N00B

    Bazinga! Thank you!

+ 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