Listbox with filter data

bmrsalgas

New Member
Joined
Aug 11, 2017
Messages
26
Hi can anyone help me with this?

I have a listbox that I already populate using the properties panel, however I need it to filter data using as filter data from a textbox.

can anyone help please.:confused::confused:
 
Thanks for the help it worked in perfection :)

See the Forum Use Guidelines last item for posting tips. https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html

I did not see the answer to post #2's column to filter. I used column 3, "C". I only listed columns A:D since I did not see an answer to that either.

Obviously, ControlSource for Textbox1 would be N5.

In the Userform:
Code:
Private Sub UserForm_Initialize()
  FilterListBox1
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  FilterListBox1
End Sub

Private Sub FilterListBox1()
  Dim r As Range
  On Error Resume Next
  With Worksheets("JobData")
    Set r = .Range("A1:D" & .Cells(Rows.Count, "A").End(xlUp).Row)
    r.AutoFilter 3, TextBox1
    ListBox1.ColumnCount = r.Columns.Count
    ListBox1.List = cellsToArray(r.SpecialCells(xlCellTypeVisible))
    r.AutoFilter
  End With
End Sub

In a Module:
Code:
Function cellsToArray(r As Range)
  Dim a()
  r.Copy
  a = ClipboardToArray
  cellsToArray = a
  Application.CutCopyMode = False
End Function

Function ClipboardToArray()
  Dim cb As Object 'Late Binding for MsForms.DataObject
  'Dim cb As New MsForms.DataObject 'Early Binding
  Dim s() As String, ss() As String, se As String, a()
  Dim i As Long, j As Long
  'Late Binding
  Set cb = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

  'On Error GoTo AnError

  'Get data from the clipboard.
  cb.GetFromClipboard
  'Get clipboard contents
  se = cb.GetText(1)
  'Split se, delimiter vbcrlf
  s() = Split(se, vbCrLf)
  ss() = Split(s(0), vbTab)
  ReDim a(LBound(s) To UBound(s), LBound(ss) To UBound(ss))
  '~~> Split each strArray and store in strArray2, delimiter " ".
  For i = LBound(s) To UBound(s)
    ss = Split(s(i), vbTab)
    For j = LBound(ss) To UBound(ss)
      a(i, j) = ss(j)
    Next j
  Next i
  ClipboardToArray = a()

  Exit Function
AnError:
  If Err <> 0 Then Debug.Print Err.Description
End Function
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,992
Messages
6,122,631
Members
449,095
Latest member
bsb1122

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