Message box to appear on Userform if search item not found- Userform Macro

  • Hi
    I have a code which I am trying to work with to show message box pop up on userform when search function does not return item from the sheet2 of the data. Below is a workable code that do the search and put the items in respective text boxes; When does not found any item it doesn't return anything and I would need to show pop up message that " Item not found".



    Not sure what to do to show message box when I item not found in the data set.
    Prompt help will be highly appreciated.
    Thanks

  • Re: Message box to appear on Userform if search item not found- Userform Macro


    You could simply check if Textbox2 is blank after the search... of course you need to choose a column which is guaranteed to have information in it. You could also declare a Boolean variable and set it True if the item is found. At the end you check if it is still False (It has a default value of False when declared) then show the message box.


    Finally you could do it the 'proper' way - Use Worksheet functions to find the data and proceed accordingly.



    PS: Your post on the discussion board has been deleted to keep things tidy.

  • Re: Message box to appear on Userform if search item not found- Userform Macro


    awesome...working smooth :) many thanks cytop :)


    Quick question, can this code be alter to look for matching record as you type in the search field? e.g. if I am looking for Department ID, and as I am typing "Dep" and it start showing me matching options for Department Code, Department Person, etc.? Greatly appreciate your help here.

  • Re: Message box to appear on Userform if search item not found- Userform Macro


    Yes, but I wouldn't have done it that way... One of the tricks of posting in forums is get your question sorted before posting and include all the relevant information. Tacking on another request later sometimes affects any solutions already posted.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!