CorperateCiv
New Member
- Joined
- Jul 19, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hello, I created a search box in excel to filter data in different tables that are listed in the spreadsheet.
This is the code I have so far:
This works to filter all the tables so that I can search for the value. However, I want to make it so that any table that does not contain the value appears hidden in the excel sheet to create a cleaner view. I was planning on using an IF statement and .hidden but I don't know how to refer to the Autofilter Value.
For example:
If the value is in the top tables:
If the value is in one of the bottom tables
The sheet also contains a lot of tables so any filtered value on the bottom, you need to scroll down to look. I would appreciate any suggestions or reccomendations that you have!
This is the code I have so far:
VBA Code:
Private Sub TextBox1_Change()
Dim tb As ListObject
Dim tb_End As Integer
Dim i As Integer
tb_End = ActiveSheet.ListObjects().Count
Application.ScreenUpdating = False
For i = 1 To tb_End
ActiveSheet.ListObjects(i).DataBodyRange.AutoFilter _
Field:=1, _
Criteria1:=[E2] & "*", _
Operator:=xlFilterValues
Next i
Application.ScreenUpdating = True
End Sub
This works to filter all the tables so that I can search for the value. However, I want to make it so that any table that does not contain the value appears hidden in the excel sheet to create a cleaner view. I was planning on using an IF statement and .hidden but I don't know how to refer to the Autofilter Value.
For example:
If the value is in the top tables:
If the value is in one of the bottom tables
The sheet also contains a lot of tables so any filtered value on the bottom, you need to scroll down to look. I would appreciate any suggestions or reccomendations that you have!