Good Day,
I am trying to write a code for a search button which searches a listbox based a specific input set in a textbox. The values searched are number or words, and the listbox contains values from a single column. The code i found below(ctto) but i don't understand why it only works for the first column of my list box.
Private Sub SearchButton_Click()
Dim SearchCriteria, i, n As Double
SearchCriteria = Me.SearchBox.Value
n = AvailableNumberList.ListCount
For i = 0 To n - 1
If Left(AvailableNumberList.List(i),Len(SearchCriteria))=SearchCriteria Then
AvailableNumberList.ListIndex = i
Exit For
End If
Next i
End Sub
I am trying to write a code for a search button which searches a listbox based a specific input set in a textbox. The values searched are number or words, and the listbox contains values from a single column. The code i found below(ctto) but i don't understand why it only works for the first column of my list box.
- SearchButton: A Button which upon clicking is supposed to initiate the search
- SearchBox: The textbox which will contain the search value
- AvailableNumberList: The listbox which contains the data
- About 20 Columns in Total but I just want to search from Column A to G
Private Sub SearchButton_Click()
Dim SearchCriteria, i, n As Double
SearchCriteria = Me.SearchBox.Value
n = AvailableNumberList.ListCount
For i = 0 To n - 1
If Left(AvailableNumberList.List(i),Len(SearchCriteria))=SearchCriteria Then
AvailableNumberList.ListIndex = i
Exit For
End If
Next i
End Sub