Hi, I want to create a search box to make it easier for my colleague to find information from 1 table. However, from my current vba module, they need to know the exact starting word to find what they are looking for. How can I set it so that they can only write certain words in the name? For example, they can just key in “motor”, in other to look for list “air bearing motor”.
VBA Code:
Sub Searchable_List()
Dim Mainsheet As Worksheet
Dim Inventory As ListObject
Set Mainsheet = Sheets("Search")
Set Inventory = Mainsheet.ListObjects("Inventory")
UserInput = Mainsheet.Range("C3") & "*"
Fieldname = Mainsheet.Range("C5").Value
'Check if there is any user input.
If UserInput <> "" Then
'User input a value,so,proceed
'Clear any filters.
Inventory.AutoFilter.ShowAllData
'Apply new filters.
If Fieldname = "Part Number" Then
'Filter by Part Number
Inventory.Range.AutoFilter Field:=1, Criteria1:=UserInput
ElseIf Fieldname = "Part Name" Then
'Filter by Part Name
Inventory.Range.AutoFilter Field:=2, Criteria1:=UserInput
ElseIf Fieldname = "Material Code" Then
'Filter by Material Code
Inventory.Range.AutoFilter Field:=3, Criteria1:=UserInput
End If
End If
End Sub