How To Make A Basic Excel VBA UserForm Search Box

In this example I am going to show you how to query your worksheet for particular information using a UserForm.

Basically we are going to have a worksheet with data in it, and ask it a simple question:

“Does the criteria I selected in the UserForm exist in the worksheet?”

Here is a simple image of the worksheet:

Excel_VBA_UserForm_Search_Box_1

…and here is the simple UserForm which is shown whenever the “Search” button is clicked:

Excel_VBA_UserForm_Search_Box_2

When the UserForm “intializes” the comboboxes are filled in:

Excel_VBA_UserForm_Search_Box_3

Here is the code I am using:

Since I am using the “Load” feature in multiple places, I am putting all the code in the “LoadBoxes” procedure.

After making my selections, I click on the “Search” button and a SQL statement is executed and a records found count is taken.

Excel_VBA_UserForm_Search_Box_4

Here is the SQL statement I am using:

Excel views data that is formatted in consecutive columns as a table. So if I want to select the data from the entire sheet I can just use “[Sheet1$]”

However, since I want the ability to query individual columns, I need to set up a “named range”.

So here is the code all together:

Let me know if you have any questions.

I consent to having this website store my submitted information so they can respond to my inquiry. See our privacy policy to learn more how we use data.
 

****************************************************


 

Please remember to subscribe to my youtube channel

Been helped? Get these!

Facebooktwittergoogle_plusredditpinterestlinkedinmail