Search Filename With Userform(Textbox1) Multiple Criteria

epoiezam

New Member
Joined
Jan 28, 2016
Messages
36
Office Version
  1. 2016
Platform
  1. Windows
Goodday Guys:

Can a textbox be used as a multiple criteria filter. (filenames in a Dir)
If Yes, can you please share the code. Thank you

Example:-
Current Dir
1) Project Japan and Korea
2) Project Poland and Norway
3) Project China and India

Filter/Search:
Textbox1 value = Norway Poland

Result:
Project Norway and Poland
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Where do you want the result?
Hi Dante.

The result will be displayed in Userform8-Listbox1 field
Fyi, I've got this part covered.

Only a bit stuck with the multiple filter codes. (Textbox1)

:)
 
Upvote 0
Below is my current code:-

UserForm8.ListBox1.Clear
Filename = Dir("\\D18090\Dictionary\" & "*" & Me.TextBox1.Value & "*" & "*")
Do While Len(Filename) > 0
UserForm8.ListBox1.AddItem Filename
Filename = Dir()
Loop
 
Upvote 0
Try this

VBA Code:
Private Sub CommandButton1_Click()
  Dim wFile As Variant, wPath As String, dict As Object, wItem As Variant
  If TextBox1.Value = "" Then
    MsgBox "Fill textbox"
    TextBox1.SetFocus
    Exit Sub
  End If
  ListBox1.Clear
  wPath = "\\D18090\Dictionary\"
  
  Set dict = CreateObject("scripting.dictionary")
  For Each wItem In Split(TextBox1, " ")
    wFile = Dir(wPath & "*" & wItem & "*" & "*")
    Do While wFile <> ""
      If Not dict.exists(wFile) Then
        dict.Item(wFile) = Empty
        ListBox1.AddItem wFile
      End If
      wFile = Dir()
    Loop
  Next
End Sub
 
Upvote 0
Hi Dante:

Thank you. But the said code doesn't work. Nothing happen even for the normal filter
 
Upvote 0
Can you put a real sample of the names of your files and what did you put in the textbox?

You can also try another folder on the same disk where you have the file with the macro.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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