Hi,
I have created a userform from an online tutorial. I got it working but when I search for a number it can't seem to find it. With text it has no problem. I am using it to search SKU #, some are just numbers and some have a combination of numbers and letter.
This is the code. How can it be modified to search for numbers, text or a combination of numbers and text?
I have created a userform from an online tutorial. I got it working but when I search for a number it can't seem to find it. With text it has no problem. I am using it to search SKU #, some are just numbers and some have a combination of numbers and letter.
This is the code. How can it be modified to search for numbers, text or a combination of numbers and text?
HTML:
Private Sub cmdContact_Click()
'dim the variables
Dim Crit As Range
Dim FindMe As Range
Dim DataSH As Worksheet
'error handler
On Error GoTo errHandler:
'set object variables
Set DataSH = Sheet1
'hold in memory and stop screen flicker
Application.ScreenUpdating = False
If Me.cboHeader.Value <> "All_Columns" Then
If Me.txtSearch = "" Then
DataSH.Range("L9") = ""
Else
DataSH.Range("L9") = "*" & Me.txtSearch.Value & "*"
End If
End If
'if all columns is selected
If Me.cboHeader.Value = "All_Columns" Then
'find the value in the column
Set FindMe = DataSH.Range("B9:I30000").Find(What:=txtSearch, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False)
'variable for criteria header
Set Crit = DataSH.Cells(8, FindMe.Column)
'if no criteria is added to the search
If Me.txtSearch = ""
Then DataSH.Range("L9") = ""
DataSH.Range("L8") = ""
Else
'add values from the search
DataSH.Range("L8") = Crit
If Crit = "ID" Then
DataSH.Range("L9") = Me.txtSearch.Value Else DataSH.Range("L9") = "*" & Me.txtSearch.Value & "*"
End If
'show in the userform the header that is added
Me.txtAllColumn = DataSH.Range("L8").Value
End If
End If
'filter the data
DataSH.Range("B8").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _ CriteriaRange:=Range("Data!$L$8:$L$9"), CopyToRange:=Range("Data!$N$8:$U$8"), _ Unique:=False
'add the dynamic data to the listbox
lstEmployee.RowSource = DataSH.Range("outdata").Address(external:=True)
'error handler
On Error GoTo 0 Exit SuberrHandler:
'if error occurs then show me exactly where the error occurs
MsgBox "No match found for " & txtSearch.Text
'clear the listbox if no match is found
Me.lstEmployee.RowSource = ""
Exit Sub
End Sub