Hi, I've been having trouble with part of my code. It seems to be partially working. I am creating a loop within a loop. I am searching for the work order number from "this workbook" in a different workbook. I have listed out the tasks of my code below. For some reason, it is operating at 100%. During my data validations, I found that the code is sometimes generating a po number that had no relation to the work order it was supposed to be looking up.
-take each work order from "maximo" worksheet (this workbook) column B
-Search the for the work order in the active sheet column B
-If multiple matchs are found, search column c for the newest date
-once found the newest date, select the value in column A of that row
-input the value into the corresponding column a of "maximo" worksheet (this workbook) that the work order was orginally selected to search for.
-Move on to the next cell in "maximo" worksheet (this workbook) to start loop again.
Any help would be greatly appreciated. Code pasted below.. Having trouble installing the plug in
Sub PoSelection()
Dim mlastRow As Long
Dim mlastColumn As Long
Dim plastRow As Long
Dim plastColumn As Long
Dim mwo As String
Dim WO As String
Dim Po As String
Dim newestDate As Date
Dim pwoRow As Long 'Po tracker work order
Dim mwoRow As Long 'Maximo file work order
mlastRow = ThisWorkbook.Worksheets("Maximo").Cells(Rows.Count, 1).End(xlUp).row 'Maximo (this workbook) ws range
mlastColumn = ThisWorkbook.Worksheets("Maximo").Cells(Columns.Count, 3).End(xlToLeft).Column
plastRow = Cells(Rows.Count, 1).End(xlUp).row 'po tracker ws range
plastColumn = Cells(Columns.Count, 3).End(xlToLeft).Column
For mwoRow = 2 To mlastRow
mwo = ThisWorkbook.Worksheets("Maximo").Range("B" & mwoRow).Value
For pwoRow = 2 To plastRow
If InStr(1, Range("B" & pwoRow).Value, mwo) > 0 Then
If CDate(Range("C" & pwoRow).Value) > newestDate Then
Po = Range("A" & pwoRow).Value
WO = Range("B" & pwoRow).Value
newestDate = CDate(Range("C" & pwoRow).Value)
End If
End If
Next pwoRow
ThisWorkbook.Worksheets("Maximo").Range("A" & mwoRow).Value = Po
Next mwoRow
End Sub
-take each work order from "maximo" worksheet (this workbook) column B
-Search the for the work order in the active sheet column B
-If multiple matchs are found, search column c for the newest date
-once found the newest date, select the value in column A of that row
-input the value into the corresponding column a of "maximo" worksheet (this workbook) that the work order was orginally selected to search for.
-Move on to the next cell in "maximo" worksheet (this workbook) to start loop again.
Any help would be greatly appreciated. Code pasted below.. Having trouble installing the plug in
Sub PoSelection()
Dim mlastRow As Long
Dim mlastColumn As Long
Dim plastRow As Long
Dim plastColumn As Long
Dim mwo As String
Dim WO As String
Dim Po As String
Dim newestDate As Date
Dim pwoRow As Long 'Po tracker work order
Dim mwoRow As Long 'Maximo file work order
mlastRow = ThisWorkbook.Worksheets("Maximo").Cells(Rows.Count, 1).End(xlUp).row 'Maximo (this workbook) ws range
mlastColumn = ThisWorkbook.Worksheets("Maximo").Cells(Columns.Count, 3).End(xlToLeft).Column
plastRow = Cells(Rows.Count, 1).End(xlUp).row 'po tracker ws range
plastColumn = Cells(Columns.Count, 3).End(xlToLeft).Column
For mwoRow = 2 To mlastRow
mwo = ThisWorkbook.Worksheets("Maximo").Range("B" & mwoRow).Value
For pwoRow = 2 To plastRow
If InStr(1, Range("B" & pwoRow).Value, mwo) > 0 Then
If CDate(Range("C" & pwoRow).Value) > newestDate Then
Po = Range("A" & pwoRow).Value
WO = Range("B" & pwoRow).Value
newestDate = CDate(Range("C" & pwoRow).Value)
End If
End If
Next pwoRow
ThisWorkbook.Worksheets("Maximo").Range("A" & mwoRow).Value = Po
Next mwoRow
End Sub