通过检查另一个工作簿的值来检查是否收到了交货?

我有两个工作簿

主人和奴隶

主:

在这里输入图像说明

H列(含交货周或交货date)

49 51 12/12/2016 etc. 

列I(包含项目编号)

 1234 1234 2222 4444 

我的奴隶工作簿看起来像这样:

在这里输入图像说明

在这个工作簿中

 Column D contains my delivery week or date. Column J contains my item number. And Column AX contains number of deliveries. 

我试图检查我的主工作表,以查看列I中的项目编号和列H中的交付date/星期是否与从属工作簿中列J中的项目编号和列D中的交付date/星期匹配。

如果这些匹配,如果AX列中的相应单元格中存在交货数量(即单元格值大于0或不为空),我想获取该结果并将其插入到我的主工作表的N列中。

这几乎奏效,但有时我有一个或多个相同的项目编号(请参阅主工作簿的图像,黄色突出显示的行)。

在这里输入图像说明

在这种情况下,项目编号4555存在2次。 在2017年3月1日交付,并于05/01/2017交付。

这个项目的交付在03/01/2017为100个案件。 然而,05/01/2017这个项目的交付是0。

出于某种原因,代码将两个交货date的商品编号标识为“订单已收到”/“订单已收到”。

这是错误的,因为这个项目在05/01/2017的交付从未发生过。

这是我的代码:

  Option Explicit Option Compare Text ------------------ 'Sub 'Check if order recieved Dim oCell As Range, oCell2 As Range, oCell3 As Range, targetCell As Range Dim ws2 As Worksheet Dim lastRow2 As Long Dim value23 As String If Not GetWb("Depot Memo", ws2) Then Exit Sub lastRow2 = Range("I" & Rows.Count).End(xlUp).Row value23 = ">0" With ws2 For Each targetCell In Range("I10:I" & lastRow2) Set oCell = .Range("J6", .Cells(.Rows.Count, "J").End(xlUp)).Find(what:=targetCell.Value, LookIn:=xlValues, lookat:=xlWhole) Set oCell3 = .Range("D6", .Cells(.Rows.Count, "D").End(xlUp)).Find(what:=targetCell.Offset(0, -1).Value, LookIn:=xlValues, lookat:=xlWhole) If Not oCell Is Nothing And Not oCell3 Is Nothing Then If oCell.Offset(, 40).Value <> "" Then Application.EnableEvents = False targetCell.Offset(0, 5).Value = "Order Already Received" targetCell.Offset(0, 4).Value = "Order Already Received" targetCell.Offset(0, 3).Value = "Order Already Received" Application.EnableEvents = True End If End If Next End With Application.ScreenUpdating = True Application.DisplayStatusBar = True Application.EnableEvents = True ActiveSheet.EnableCalculation = True ActiveSheet.DisplayPageBreaks = False End Sub Function GetWb(wbNameLike As String, ws As Worksheet) As Boolean Dim wb As Workbook For Each wb In Workbooks If wb.Name Like "*" & wbNameLike & "*" Then '<-- check if workbook name contains "Depot Memo" Set ws = wb.Worksheets(1) Exit For End If Next GetWb = Not ws Is Nothing End Function 

请有人告诉我我要去哪里错了吗?