Hi, Master Mikerickson
After verifying the result. Found there is problem when enter info with "empty Option. And I am try to analysis the code. But due to weak in VBA, I still need your helps to advice. Thanks.
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
If Trim(Me.txtmodel.Value) = "" Then
Me.txtmodel.SetFocus
MsgBox "Please Enter a Model Number"
Exit Sub
End If
With ws
.Cells(iRow, 1).Value = Me.txtmodel.Value
.Cells(iRow, 2).Value = Me.txtOption.Value
End With
Me.txtmodel.Value = ""
Me.txtOption.Value = ""
Me.txtmodel.SetFocus
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub txtmodel_AfterUpdate()
Call Input_AfterUpdate
End Sub
Private Sub txtOption_AfterUpdate()
Call Input_AfterUpdate
End Sub
Private Sub Input_AfterUpdate()
If txtOption.Text = vbNullString Or txtmodel.Text = vbNullString Then
TextBox1.Text = " * - * "
Else
txtOption.Text = SortAndDelimit(txtOption.Text)
With Sheets("Table")
If 0 < WorksheetFunction.CountIfs(.Range("A:A"), txtmodel.Text, .Range("B:B"), txtOption.Text) Then
TextBox1.Text = " Match"
Else
TextBox1.Text = "Not Match"
End If
End With
End If
End Sub
Function SortAndDelimit(ByVal strInput As String, Optional Delimiter As String = ", ") As String
Dim i As Long, j As Long, WordCount As Long
Dim Words As Variant
For i = 1 To Len(Delimiter)
strInput = Replace(strInput, Mid(Delimiter, i, 1), vbNullString)
Next i
strInput = UCase(strInput)
WordCount = Int((Len(strInput) - 1) / 3)
ReDim Words(0 To WordCount)
For i = 0 To UBound(Words)
Words(i) = Mid(strInput, 3 * i + 1, 3)
Next i
For i = 0 To WordCount - 1
For j = i + 1 To WordCount
If Len(Words(i)) < Len(Words(j)) Then
GoSub Swap
ElseIf Len(Words(i)) = Len(Words(j)) Then
If (Words(j) < Words(i)) Then GoSub Swap
End If
Next j
Next i
SortAndDelimit = Join(Words, Delimiter)
Exit Function
Swap:
strInput = Words(i)
Words(i) = Words(j)
Words(j) = strInput
Return
End Function
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the Exit button!"
End If
End Sub