UserForm Searchable Listbox

Joined
Apr 17, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone.

I am currently trying to do an entirely new job system for work and I need help.
I have a list box in a user form that is already populated with my data range. Is it possible to create a search bar for this list box that will allow me to search for specific data within the list box while in the user form?

Thank you and any help will be much appreciated. I feel like a fish out of water.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello. I show you a simple model:
Test_3.xlsm
\___________________/​

VBA Code:
Option Explicit
Dim tb As ListObject

Private Sub UserForm_Initialize()
Set tb = Range("tbl_Main").ListObject
'-------------->
ComboBox1.List = Array("TIt1", "Tit2")
'-------------->
mFilter
End Sub

Private Sub mFilter()
Dim a, i&, b, j%
'-------------->
ListBox1.Clear
If tb.ListRows.Count = 0 Then Exit Sub
'-------------->
If ComboBox1.ListIndex = -1 Then Exit Sub
'-------------->
With tb
  b = .ListColumns(CStr(ComboBox1)).DataBodyRange.Address
  a = .Parent.Evaluate(Replace("If(IsNumber(Search(""" & TextBox1 & """, |)), Row(|) - " & .HeaderRowRange.Row & " )", "|", b))
  a = Filter(Application.Transpose(a), False, False)
  If UBound(a) < 0 Then Exit Sub
'-------------->
  ReDim b(0 To UBound(a), 1 To 4)
  For i = 0 To UBound(a)
    b(i, 1) = .DataBodyRange(a(i), 1)
    b(i, 2) = .DataBodyRange(a(i), 2)
    b(i, 3) = Format(.DataBodyRange(a(i), 3), "Short Date")
    b(i, 4) = Format(.DataBodyRange(a(i), 4), "Currency")
  Next
'-------------->
End With
ListBox1.List = b
End Sub

Private Sub ComboBox1_Change(): mFilter: End Sub
Private Sub TextBox1_Change(): mFilter: End Sub
 
Upvote 0
Thank you so much. I have put this code in but once I am done I receive a run time error '1004' method 'range' of object' global' failed. i am not sure how to fix this.
 
Upvote 0
Thank you so much. I have put this code in but once I am done I receive a run time error '1004' method 'range' of object' global' failed. i am not sure how to fix this.
Put your implementation on a public server (like MediaFire.com) and post the link to see where you couldn't adapt what was suggested.
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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