我正在尝试将一张(QTY
)中的UID
和Shipment
与另一张(Record
)进行比较。我想比较UID
是否相等然后比较QTY
,如果QTY
相等则输出"完成" 否则"不完整" 除Record
表中的记录外。
工作表Record
UID qty Shipped
234 2 incomplete
335 5
453 6
664 3 complete
787 13
工作表Shipment
UID qty
664 3
234 1
答案 0 :(得分:2)
假设您的工作表Shipment
如下
然后在工作表Cell C2
的{{1}}中输入以下公式
Record
这是一个数组公式,所以按 Ctrl + Shift + Enter 提交它。根据需要拖动/复制。查看图像以供参考。
答案 1 :(得分:1)
非数组公式,允许完整列引用并正常输入:
=IF(ISNUMBER(MATCH(A2,Shipment!A:A,0)),IF(COUNTIFS(Shipment!A:A,A2,Shipment!B:B,B2),"Complete","Imcomplete"),"")
或者这个较短的版本:
=IFERROR(IF(INDEX(Shipment!B:B,MATCH(A2,Shipment!A:A,0)) = B2,"Complete","Imcomplete"),"")
答案 2 :(得分:0)
您不能在同一个单元格中同时拥有值和公式。 您将需要VBA来实现您想要实现的目标。
试试这个..
Sub GetQtyStatus()
Dim sws As Worksheet, dws As Worksheet
Dim Rng As Range, Cell As Range
Dim lr As Long, r As Long
Application.ScreenUpdating = False
Set sws = Sheets("Shipment")
Set dws = Sheets("Record")
lr = dws.Cells(Rows.Count, 1).End(xlUp).Row
Set Rng = dws.Range("A2:A" & lr)
For Each Cell In Rng
If Application.CountIf(sws.Columns(1), Cell.Value) > 0 Then
r = Application.Match(Cell.Value, sws.Columns(1), 0)
If Cell.Offset(0, 1) = sws.Cells(r, 2) Then
Cell.Offset(0, 2) = "Complete"
Else
Cell.Offset(0, 2) = "Incomplete"
End If
End If
Next Cell
Application.ScreenUpdating = True
End Sub
如何实施代码:
如何运行代码:
该代码假定工作簿中有两个名为Record和Shipment的工作表,UID和Qty分别列在工作表的A和B列中。