Hello,
I have been trying to get the code below to work for a while now and am pretty much stuck.
What I have made is a userform that the user inputs a job # and seq # (columns A and B), and it will search for those two user values and print out columns A B C D into the userform BOX.
I have gotten this to work by only using one of the values (JOB) , however I am stumped as to how to search another column (column B) to get the row that has that JOB AND SEQ.
For example, here is how the table will look:
JOB SEQ MACHINE 1 MACHINE 2
100 202 MAT MAT
100 204 MAT MAT
I want the user to type in
JOB : 100
SEQ 202
and see in the box
100 202 MAT MAT
Here is what I have so far:
Private Sub cmdFind_Click()
Dim searchText As Variant, FirstAddr As String, searchText1 As String
Dim FoundCell As Range, LastCell As Range, searchRange As Range, searchrange1 As Range
Dim i As Integer, endRow As Long
Dim foundTarget As Boolean
searchText = Array(JOBS.Text, SEQ.Text)
'If Len(searchText) = 0 Then Exit Sub
Application.ScreenUpdating = False
Worksheets("jobs").Select
Range("A1:B1000").End(xlDown).Select
endRow = ActiveCell.Row
Range("A1:B1000").Select
Application.ScreenUpdating = True
Worksheets("jobs").Select
Set searchRange = Range("A2:B1000")
Me.lstCustSearch.Clear
foundTarget = True
With searchRange
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = searchRange.Find(what:=searchText, after:=LastCell)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
Else
foundTarget = False
End If
i = 0
Do Until FoundCell Is Nothing
Me.lstCustSearch.AddItem Cells(FoundCell.Row, 1).Value
Me.lstCustSearch.List(i, 1) = Cells(FoundCell.Row, 2).Value
Me.lstCustSearch.List(i, 2) = Cells(FoundCell.Row, 3).Value
Me.lstCustSearch.List(i, 3) = Cells(FoundCell.Row, 4).Value
Set FoundCell = searchRange.FindNext(after:=FoundCell)
If FoundCell.Address = FirstAddr Then
Exit Do
End If
i = i + 1
Loop
If Not foundTarget Then
MsgBox "No data found for " & searchText
Else
Me.JOBS.Text = ""
End If
Me.JOBS.SetFocus
End Sub
Thanks for anyones help
Bookmarks