+ Reply to Thread
Results 1 to 11 of 11

Error on Button when no Value on Vlookup

  1. #1
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Error on Button when no Value on Vlookup

    Hi,

    I have a simple spreadsheet that uses Vlookup.


    I used a textbox to search a data, use a button to search, then display the value on a label
    it works okay, but when I search and value is not found.. I received an error when I clicked the button

    "Run-time error '13':
    Type mismatch



    This is my code:

    Private Sub CommandButton1_Click()
    Sheets("Summary").Range("A3") = TextBox1.Value
    Label1.Caption = Sheets("Summary").Range("A4")
    Label3.Caption = Sheets("Summary").Range("A5")
    End Sub


    I'm planning to display "Record not Found" if no value is found on the search.


    Thanks in advance
    -L

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Error on Button when no Value on Vlookup

    At which point in your code do you get the error?
    It's a mismatch, so much is clear but which variable?
    Your code (incorrectly posted since you omitted the code tags) does not tell me (us) anything
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Re: Error on Button when no Value on Vlookup

    Hi, thanks for the reply,

    the error occurs when the item I searched is not on the list. on Excel it will only display N/A, but when it run it using vba, button, text.. it received the error.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Re: Error on Button when no Value on Vlookup

    Please Login or Register  to view this content.
    the label1 is highlighted in yellow when I occurs the error

  5. #5
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Re: Error on Button when no Value on Vlookup

    Here is the sample Spreadsheet.

    On Sheet "Summary", there is a textbox, Button and Label. The Vlookup formula are found on A3,A4,A5. and these values display on Label.

    On sheet "Data", this is where the data are searched. ID numbers are on column C, if you search the correct ID#, it returns the values correctly, But when the ID# is incorrect it shows me error.
    I would like to code it that when you enter incorrect ID#, it will display on the label "Record not Found"


    Sincererely
    -L
    Attached Files Attached Files

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Error on Button when no Value on Vlookup

    Try this way.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 08-25-2018 at 06:25 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Error on Button when no Value on Vlookup

    You have add an error trap, something like on error resume next
    After that line you check if Err.number > 0 that means there is an error, just like the way you would in a normal formula
    I’m writing this on my phone so no excel at hand but it’s just to give you an idea

  8. #8
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Re: Error on Button when no Value on Vlookup

    Quote Originally Posted by bakerman2 View Post
    Try this way.
    Please Login or Register  to view this content.


    Hi thank you for the reply.
    It only shows record not found even the input is correct

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Error on Button when no Value on Vlookup

    Oeps, don't know what went wrong here.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-12-2018
    Location
    DRC
    MS-Off Ver
    2013
    Posts
    33

    Re: Error on Button when no Value on Vlookup

    Hi, That works smoothly.

    Thanks for the assistance all. it helps me a lot.

    +1 Rep

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Error on Button when no Value on Vlookup

    Glad to help and sorry again for the mixup.

    Thanks for rep+.

+ 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. Concatenate error across 2 worksheets with vlookup error
    By COGICPENNY in forum Excel General
    Replies: 2
    Last Post: 11-30-2015, 07:56 PM
  2. How to error trap a vlookup that returns an error or #N/A
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 12:01 PM
  3. [SOLVED] lookup - if(is error(vlookup and error messages meanings
    By grphillips in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-18-2013, 07:03 PM
  4. Application Defined or Object Defined Error, Command Button and Vlookup Function
    By stevedomer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-14-2011, 11:20 PM
  5. error 1004 application defined error (Moving click button)
    By mdavid800 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2011, 10:13 AM
  6. run-time error '91'-Close Button error
    By ASCO IS Help in forum Excel General
    Replies: 1
    Last Post: 05-08-2006, 11:30 AM
  7. run-time error '91' - Close Button Error
    By ASCO IS Help in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2006, 01:10 PM

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