Hello, I'm sorry if my Title question is not clear as I don't know how to properly put it in English.
Here is what I mean :
Suppose that I have a range named ITEM which content :
Fish Snapper Red
Fish Baramundi
Fish Snapper Fillet
Fish Snapper White Fillet
Fish Snapper Red Fillet
Fish Salmon Fillet
Chicken Neck
Chicken Fillet
Pork Loin Rack
Pork Minced
Pork Neck Boneless
Pork Oxtail
Lamb Minced Local
Lamb Neck Boneless
What I want is....
if the user type "fillet" - then all the data contains "fillet" will show :
Fish Snapper Fillet
Fish Salmon Fillet
Chicken Fillet
Fish Snapper White Fillet
if the user type "fish" - then all the data contains "fish" will show.
if the user type "snapper red" OR "red snapper" - then the list show :
Fish Snapper Red
Fish Snapper Red Fillet
if the user type "neck boneless" OR "boneless neck" then all the list show :
Pork Neck Boneless
Lamb Neck Boneless
and so on.
Below is a code for the User Form which I found from the internet.
To be honest, I don't know/understand the code but it works well if the user type one word or two words that match in the data.
From the code above - if I search by typing (for example) "fish" then all the data contains the word "fish" will show.
If I type "snapper red" then all the data contains "snapper red" will show.
But if I search by typing
then it won't find anything.
The thing that I want to achieve is if I type
then it will also show the data which contains those two words. So it doesn't care the order of the words, even if the Item name is (for example) Red Fillet Fish Snapper it will show when I type either
or
.
Something like if a user type in the Google Search box either
or
then the search result contains those two words (doesn't matter where the position is) will show. Only if the user type in the Google Search box with apostrophe
then the result which contains
will show.
So, is it doable ?
If it's doable, how is the code ?
(If it's not doable, please forget my question)
Any kind of respond would be greatly appreciated.
Thank you in advanced.
Here is what I mean :
Suppose that I have a range named ITEM which content :
Fish Snapper Red
Fish Baramundi
Fish Snapper Fillet
Fish Snapper White Fillet
Fish Snapper Red Fillet
Fish Salmon Fillet
Chicken Neck
Chicken Fillet
Pork Loin Rack
Pork Minced
Pork Neck Boneless
Pork Oxtail
Lamb Minced Local
Lamb Neck Boneless
What I want is....
if the user type "fillet" - then all the data contains "fillet" will show :
Fish Snapper Fillet
Fish Salmon Fillet
Chicken Fillet
Fish Snapper White Fillet
if the user type "fish" - then all the data contains "fish" will show.
if the user type "snapper red" OR "red snapper" - then the list show :
Fish Snapper Red
Fish Snapper Red Fillet
if the user type "neck boneless" OR "boneless neck" then all the list show :
Pork Neck Boneless
Lamb Neck Boneless
and so on.
Below is a code for the User Form which I found from the internet.
To be honest, I don't know/understand the code but it works well if the user type one word or two words that match in the data.
Code:
Private Sub FoundNameBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim ws As Worksheet
If KeyAscii = 13 Then
Set ws = Worksheets("DAILY")
ws.Range("h2").Value = Me.FoundNameBox.Value
ws.Range("e16").Select
Unload Me
End If
ActiveSheet.Protect
End Sub
Private Sub FoundNameBox_Click()
Dim ws As Worksheet
Set ws = Worksheets("DAILY")
ws.Range("h2").Value = Me.FoundNameBox.Value
ws.Range("e16").Select
End Sub
Private Sub OK_button_Enter()
Unload Me
End Sub
Private Sub UserForm_Activate()
Dim arTemp() As String 'Temp Array
Dim bFound As Boolean 'Flag
Dim i1 As Integer 'Array Counter
Dim cari As String
Dim lingkup As String
lingkup = "ITEM" 'range name of the items
Sheets("TABLE").Activate
cari = InputBox("Type a word you want to find")
bFound = FindAll(cari, ActiveSheet, lingkup, arTemp())
If bFound = True Then
For i1 = 1 To UBound(arTemp)
result = Range(arTemp(i1)).Value
FoundNameBox.AddItem result
Next i1
Else
MsgBox "The word that you are looking for has no match"
End If
Sheets("DAILY").Activate
If Me.FoundNameBox.ListCount = 0 Then
Unload Me
Else
FoundNameBox.ListIndex = 0
End If
End Sub
Function FindAll(ByVal sText As String, ByRef oSht As Worksheet, ByRef sRange As String, ByRef arMatches() As String) As Boolean
' --------------------------------------------------------------------------------------------------------------
' FindAll - To find all instances of the given string and return the row numbers.
' If there are not any matches the function will return false
' --------------------------------------------------------------------------------------------------------------
On Error GoTo Err_Trap
Dim rFnd As Range ' Range Object
Dim iArr As Integer ' Counter for Array
Dim rFirstAddress ' Address of the First Find
' -----------------
' Clear the Array
' -----------------
Erase arMatches
Set rFnd = oSht.Range(sRange).Find(What:=sText, LookIn:=xlValues, LookAt:=xlPart)
If Not rFnd Is Nothing Then
rFirstAddress = rFnd.Address
Do Until rFnd Is Nothing
iArr = iArr + 1
ReDim Preserve arMatches(iArr)
arMatches(iArr) = rFnd.Address ' rFnd.Row ' Store the Row where the text is found
Set rFnd = oSht.Range(sRange).FindNext(rFnd)
If rFnd.Address = rFirstAddress Then Exit Do ' Do not allow wrapped search
Loop
FindAll = True
Else
' ----------------------
' No Value is Found
' ----------------------
FindAll = False
End If
' -----------------------
' Error Handling
' -----------------------
Err_Trap:
If Err <> 0 Then
'MsgBox Err.Number & " " & Err.Description, vbInformation, "Find All"
Err.Clear
FindAll = False
Exit Function
End If
End Function
From the code above - if I search by typing (for example) "fish" then all the data contains the word "fish" will show.
If I type "snapper red" then all the data contains "snapper red" will show.
But if I search by typing
Code:
red snapper
The thing that I want to achieve is if I type
Code:
red snapper
Code:
red snapper
Code:
snapper red
Something like if a user type in the Google Search box either
Code:
red snapper
Code:
snapper red
Code:
"snapper red"
Code:
snapper red
So, is it doable ?
If it's doable, how is the code ?
(If it's not doable, please forget my question)
Any kind of respond would be greatly appreciated.
Thank you in advanced.
Last edited: