✔ 最佳答案
假設sheet2的C欄及G欄有100列資料,I1的公式為:
=IF(ISNA(MATCH(C1,Sheet2!$G$1:$G$100,0)),"",INDEX(Sheet2!$C$1:$C$100,MATCH(C1,Sheet2!$G$1:$G$100,0)))
J1的公式為:
=IF(ISNA(MATCH(D1,Sheet2!$G$1:$G$100,0)),"",INDEX(Sheet2!$C$1:$C$100,MATCH(D1,Sheet2!$G$1:$G$100,0)))
如果只當I與J行的單號相同才顯示出來,I1或 J1的公式為:
=IF(OR(ISNA(MATCH(C1,Sheet2!$G$1:$G$100,0)),ISNA(MATCH(D1,Sheet2!$G$1:$G$100,0))),"",IF(INDEX(Sheet2!$C$1:$C$100,MATCH(C1,Sheet2!$G$1:$G$100,0))=INDEX(Sheet2!$C$1:$C$100,MATCH(D1,Sheet2!$G$1:$G$100,0)),INDEX(Sheet2!$C$1:$C$100,MATCH(C1,Sheet2!$G$1:$G$100,0)),""))
如G2編號出現在其他單號(即出現兩次或以上),可考慮加入兩行提示行在K和L,K1的公式為:
=IF(ISNUMBER(C1),IF(COUNTIF(Sheet2!$G$1:$G$100,C1)>1,"單號"&C1&"出現了"&COUNTIF(Sheet2!$G$1:$G$100,C1)&"次",""),"")
L1的公式為:
=IF(ISNUMBER(D1),IF(COUNTIF(Sheet2!$G$1:$G$100,D1)>1,"單號"&D1&"出現了"&COUNTIF(Sheet2!$G$1:$G$100,D1)&"次",""),"")
亦可簡化將兩行提示行合併成一行在K,K1的公式為:
=IF(ISNUMBER(C1),IF(COUNTIF(Sheet2!$G$1:$G$100,C1)>1,"單號"&C1&"出現了"&COUNTIF(Sheet2!$G$1:$G$100,C1)&"次",""),"")& IF(AND(ISNUMBER(C1), ISNUMBER(D1)), IF(AND(COUNTIF(Sheet2!$G$1:$G$100,C1)>1, COUNTIF(Sheet2!$G$1:$G$100,D1)>1),", ","") ,"")&IF(ISNUMBER(D1),IF(COUNTIF(Sheet2!$G$1:$G$100,D1)>1,"單號"&D1&"出現了"&COUNTIF(Sheet2!$G$1:$G$100,D1)&"次",""),"")