hello again, so I have another question that needs answerd
So I have a program already created that searches a specific column in data base, and then the user types in a variable name and the program selects all the rows that have that data in it. I was wondering how (and if possible) I can make it so that when you type in (for example: WD-40, WD 40 and WD40) that the program will still find the appropriate data.
I looked up something called fuzzy text that might work but I don’t understand how to get it into my current code and make it work.
I will insert a mini version of my program along with the code so you can see what mean. And note that the “large program” has over 2500 products, and 26 columns. So adding a little bit of extra code really doesn’t bother me. That and this program is used by miners who have their work gloves on so misspelled words, or similar spelled words tend to happen a lot.
Thanks in advance.
Private Sub CommandButton1_Click()
'SEARCH
Dim Cnt As Long
Dim Col As Variant
Dim FirstAddx As String
Dim FoundMatch As Range
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Dim Wks As Worksheet
StartRow = 2
Set Wks = Sheets(1)
Col = ComboBox1.ListIndex + 1
If Col = 0 Then
MsgBox "Please choose a category."
Exit Sub
End If
If TextBox1.Text = "" Then
MsgBox "Please enter a search term."
TextBox1.SetFocus
Exit Sub
End If
LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
Set Rng = Wks.Range(Wks.Cells(2, Col), Wks.Cells(LastRow, Col))
Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
After:=Rng.Cells(1, 1), _
LookAt:=xlWhole, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundMatch Is Nothing Then
FirstAddx = FoundMatch.Address
ListView1.ListItems.Clear
Do
Cnt = Cnt + 1
R = FoundMatch.Row
ListView1.ListItems.Add Index:=Cnt, Text:=R
For Col = 1 To 13
Set C = Wks.Cells(R, Col)
ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
Next Col
Set FoundMatch = Rng.FindNext(FoundMatch)
Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
SearchRecords = Cnt
Else
ListView1.ListItems.Clear
SearchRecords = 0
MsgBox "No match found for " & TextBox1.Text
End If
End Sub
Private Sub UserForm_Activate()
Dim C As Long
Dim i As Long
Dim R As Long
Dim Wks As Worksheet
ListView1.View = lvwReport
ListView1.HideSelection = False
ListView1.FullRowSelect = True
ListView1.HotTracking = True
ListView1.HoverSelection = False
ListView1.ColumnHeaders.Add Text:="Row", Width:=64
Set Wks = Sheets(1)
For C = 1 To 13
ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
ComboBox1.AddItem Wks.Cells(1, C).Text
Next C
End Sub
'SEARCH
Dim Cnt As Long
Dim Col As Variant
Dim FirstAddx As String
Dim FoundMatch As Range
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Dim Wks As Worksheet
StartRow = 2
Set Wks = Sheets(1)
Col = ComboBox1.ListIndex + 1
If Col = 0 Then
MsgBox "Please choose a category."
Exit Sub
End If
If TextBox1.Text = "" Then
MsgBox "Please enter a search term."
TextBox1.SetFocus
Exit Sub
End If
LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
Set Rng = Wks.Range(Wks.Cells(2, Col), Wks.Cells(LastRow, Col))
Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
After:=Rng.Cells(1, 1), _
LookAt:=xlWhole, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundMatch Is Nothing Then
FirstAddx = FoundMatch.Address
ListView1.ListItems.Clear
Do
Cnt = Cnt + 1
R = FoundMatch.Row
ListView1.ListItems.Add Index:=Cnt, Text:=R
For Col = 1 To 13
Set C = Wks.Cells(R, Col)
ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
Next Col
Set FoundMatch = Rng.FindNext(FoundMatch)
Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
SearchRecords = Cnt
Else
ListView1.ListItems.Clear
SearchRecords = 0
MsgBox "No match found for " & TextBox1.Text
End If
End Function
Private Sub UserForm_Activate()
Dim C As Long
Dim i As Long
Dim R As Long
Dim Wks As Worksheet
ListView1.View = lvwReport
ListView1.HideSelection = False
ListView1.FullRowSelect = True
ListView1.HotTracking = True
ListView1.HoverSelection = False
ListView1.ColumnHeaders.Add Text:="Row", Width:=64
Set Wks = Sheets(1)
For C = 1 To 13
ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
ComboBox1.AddItem Wks.Cells(1, C).Text
Next C
End Sub
Private Sub ListView1_Click()
Dim Rw As Long
On Error GoTo exit_proc
Rw = Me.ListView1.SelectedItem
ActiveWorkbook.FollowHyperlink Address:=ActiveSheet.Cells(Rw, 13).Value
exit_proc:
On Error Resume Next
End Sub
Bookmarks