Give this a try.
Option Explicit
Dim FileName As String, Plant As String
Dim SltrRw As Long, Sub1stRw As Long, SubRw As Long
Sub GetData()
Sheets("Submitted Orders").Select
Range("A2").Select
Cells.Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes ' Sort by Plant Name
FileName = Application.GetOpenFilename("Excel Files (*.xls*, *.xls*", , "Select file to open")
If FileName = "False" Then
Exit Sub
End If
Workbooks.Open (FileName)
Plant = Range("M15").Value
With ThisWorkbook.Sheets("Submitted Orders")
Sub1stRw = 0
On Error Resume Next
Sub1stRw = .Cells.Find(what:=Plant, LookIn:=xlValues, lookat:=xlWhole).Row
On Error GoTo 0
If Sub1stRw = 0 Then
MsgBox Plant & " not found in " & .Name
Exit Sub
End If
SltrRw = Range("A1").End(xlDown).Row + 1
Do Until Cells(SltrRw, 1).Value = "" ' loop through products in Slaughter Process sheet
SubRw = Sub1stRw
If Cells(SltrRw, 15).Value <> "" Then ' it has an order #
Do Until .Cells(SubRw, 2).Value = Cells(SltrRw, 1).Value Or .Cells(SubRw, 1).Value <> Plant
SubRw = SubRw + 1
Loop
If .Cells(SubRw, 2).Value = Cells(SltrRw, 1).Value Then ' found the matching product
.Cells(SubRw, 16).Value = Cells(SltrRw, 15).Value
End If
End If
SltrRw = SltrRw + 1
Loop
End With
ActiveWorkbook.Close (False)
End Sub
Bookmarks