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.
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.