Using Data entered in Textboxes in a User Form to filter a workshe

M

MiComputerGeek78

I have worksheet that has data in columns A:L. It has a header row. This
spreadsheet is going to be used by a customer to look for certain information
however there are a ton of lines of information, and using the find option is
too cumbersome for them and we aren't sure the filter option manually is good
either. So I created a user form that pops up when they click a button that
says " Click Here to Search Data". They then can fill in information in the
text boxes on the user form. There is one text box per heading. For example:
System Name is a line on the form and next to it they can enter in what to
search by in a text box. Now I have figured to tell them in a line on the
user form that to search for a word contained in any part of the cell to
enter in asteriks (i.e. *011*). However the problem is that I have a filter
macro/vb code tied to the search button that will work for filtering either
one column but can't seem to get it work for multiple lines.

Here is what I have currently:
Private Sub CommandButton1_Click()

Selection.AutoFilter Field:=1, Criteria1:=UserForm1.TextBox1, Operator:=xlAnd
End Sub

I need them to be able to enter into TextBox 1 through 12 and for it filter
based on what was entered. So in the System ID field which is TextBox 1 if
I enter *011* then it looks at the first column or basically field 1 it shows
just the lines that had 011 contained in the cell in the first column.
Which the above seems to do however the challenge then comes let's say they
don't enter in anything to filter the first column but instead enter in
something in TextBox2 to filter column 2 by then I want it to show the
results filtering column 2 by what was entered.

I tried to use something like this (changed the And & Or at the end but
still no luck):
Private Sub CommandButton1_Click()

Selection.AutoFilter Field:=1, Criteria1:=UserForm1.TextBox1,
Operator:=xlAnd
Selection.AutoFilter Field:=2, Criteria1:=UserForm1.TextBox2,
Operator:=xlAnd
End Sub

However the problem with that was it only worked if I entered data into both
TextBox1 and TextBox2 but not if I only entered data in Textbox 2.

I will admit I use Visual Basic maybe once every six months so I may be
approaching this completely the wrong way. I appreciate any help at all.
And hope that I have provided enough information for someone to help me.

Thank you in advance!!!! I feel like I'm just missing one piece and once I
have the puzzle will fall into place.
 
M

MiComputerGeek78

I wanted to add some information to try to make this as clear as possible
without being able to attach the file.

This would be the original data for example:
Fruit Name Fruit Color Fruit Price
Banana Yellow $0.25
Apple Red $1.00
Watermelon Green $1.25
Apple 2 Green $2.00

The userform is setup llike this as best I can recreate in plan text
Fruit Name [Textbox]
Fruit Color [Textbox]
Fruit Price [Textbox]


Let me know if any other information will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top