I have built a data table and a data search function for Excel using a VBA ListBox. Everything works perfectly, but now I want to add a title to the search results. Does anyone know how to do this?
Currently, the title is not included in the search results when the program runs.
I want the title to be added as in the example below:
Currently, the title is not included in the search results when the program runs.
Code:
Private Sub input_search_Change()
Dim arr(), result, i As Long, a As Long, dk As String
dk = input_search.Text
arr = Sheets("Sheet1").Range("A4:D20006").Value
ReDim result(1 To UBound(arr, 1), 1 To 6)
For i = 1 To UBound(arr, 1)
If arr(i, 2) Like "*" & dk & "*" Or _
arr(i, 4) Like "*" & dk & "*" Then
a = a + 1
result(a, 1) = arr(i, 1)
result(a, 2) = arr(i, 2)
result(a, 3) = arr(i, 3)
result(a, 4) = arr(i, 4)
End If
Next i
lstwebsite = ""
lstwebsite.Clear
lstwebsite.List = result
End Sub
Private Sub UserForm_Initialize()
lstwebsite.List = Sheets("Sheet1").Range("A4:D20006").Value
End Sub
I want the title to be added as in the example below:
Last edited: