Listbox question

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
239
Office Version
  1. 2016
Platform
  1. Windows
Hello all,

Im busy with a program to search through data and display it in a listbox.

What i've got now;

I can search in the textbox under Find product on boxnr and productname.

What i want to be added is an option to search only on box, or on product name, or year.

I got some code but that doesn't work. I even have problems with showing the column year in the listbox.

Can someone help me with this and explain it a bit so i can add even more in the future?

Code that works but where i need to include 1 more column:

Code:
Private Sub txtKeywords_Change()    Dim cl As Range
    Dim i As Long
    Dim ZoekIn As String
    Dim wrd() As String
    
    lstSearchResults.Clear
    For Each cl In Sheets("sheet1").Range("B2:B" & Range("B2").CurrentRegion.Rows.Count)
        ZoekIn = cl.Offset(, -1) & vbTab & LCase(cl.Value)
        If InStr(1, ZoekIn, LCase(txtKeywords.Text)) > 0 Then
            ReDim Preserve wrd(i)
            wrd(i) = ZoekIn
            i = i + 1
        End If
    Next cl
    
    On Local Error GoTo Einde
    lstSearchResults.List = wrd
Einde:
End Sub


Private Sub UserForm_Initialize()
    Dim cl As Range
    Dim i As Long
    Dim wrd() As String
    
    For Each cl In Sheets("sheet1").Range("B2:B" & Range("B2").CurrentRegion.Rows.Count)
        ReDim Preserve wrd(i)
        wrd(i) = cl.Offset(, -1) & vbTab & LCase(cl.Value)
        i = i + 1
    Next cl
    
    On Local Error GoTo Einde
    lstSearchResults.List = wrd
Einde:
End Sub


I don't have an option to add files?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,912
Messages
6,175,346
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top