0
votes

I am trying to set up a userform that will filter a table immediately after a single text box is populated with the filter criteria.

The filter criteria is in a single text box (the only place to input data in this userform).

I am using a barcode scanner to populate the textbox and this criteria will then be used to filter the data in my table.

I would like the data to be filtered immediately after the textbox is populated from the barcode scanner (without having to press a command button to filter the data).

I am pretty new to programming in general, any ideas? Thanks!

I have created a userform that will filter that data, but only after I press a command button to filter it. I would like this to happen automatically after the barcode scanner inputs the data.

UPDATE I have moved the code to the sub below and gotten rid of the command button. Now I would like to be able to hide the userform automatically after the data is filtered. When I add the Userform1.Hide, all the filters are removed from my table, but when I comment this line out, it works fine (but the userform remains unhidden). Any ideas?

Option Explicit Private Sub TextBox1_Change()

ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:=TextBox1.Value

Userform1.Hide

End Sub

1

1 Answers

0
votes

The Private Sub TextBox1_Change() routine is called whevever a change is made to TextBox1, that is, for every character that is entered. So, put your code there. At each call, check that the textbox has received a complete and valid filter. If not, just return. Otherwise, run the filter (and clear the textbox to be able to receive another filter).