kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hello every one,
I have yet another challenge here:
Below is the code I am using to search for data and populate my listbox with. The input is taken from the textbox called txtSearch. But now I have another box(Combobox) called txtOption, and this has the letters A B C D or can even be blank. I am thinking of modifying the code below so that it can filter first from the txtOption then the txtSearch. So when I enter a keyword to search from the txtSearch, it will look at the keyword and display only names assigned to the option in txtOption in the listbox. I am doing the thinking but the image is not clear yet and I need someone here to help pull me out. Thanks
Kelly
I have yet another challenge here:
Below is the code I am using to search for data and populate my listbox with. The input is taken from the textbox called txtSearch. But now I have another box(Combobox) called txtOption, and this has the letters A B C D or can even be blank. I am thinking of modifying the code below so that it can filter first from the txtOption then the txtSearch. So when I enter a keyword to search from the txtSearch, it will look at the keyword and display only names assigned to the option in txtOption in the listbox. I am doing the thinking but the image is not clear yet and I need someone here to help pull me out. Thanks
Kelly
Code:
Sub Lookup()
On Error GoTo errHandler:
lstView.ColumnCount = 23
Dim myArray As Variant
myArray = [C7].Resize(, lstView.ColumnCount + 1).Value
lstView.List = myArray
lstView.Clear
sht = CmbClass.Value
With Sheets(sht).Range("C7:C110")
Set rngFind = .Find(What:=txtSearch.Text, After:=Sheets(sht).[C110], LookIn:=xlValues, lookat:=xlPart, _
SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address
Do
If rngFind.Row > 1 Then
lstView.AddItem rngFind.Offset(0, -1).Text
lstView.List(lstView.ListCount - 1, 1) = rngFind.Text
For i = 2 To 22
lstView.List(lstView.ListCount - 1, i) = rngFind.Offset(0, i - 1).Text
Next i
End If
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
Else: 'Reset1
End If
End With
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "Check your entry for errors", vbCritical, "Error Alert!"
End Sub