2013-01-04 58 views
1

我正在使用Excel 2003,並試圖比較兩列以找到不在另一列中的列中的數據。在Excel中查找缺失的數據列

例如:

enter image description here

+0

請查看這篇文章http://stackoverflow.com/questions/3998547/compare-two-columns-in-excel – Hiten004

+0

Hiten004的建議/鏈接將起作用,或者您也可以使用列B查找列A值作爲查找數組,然後按照「#n/a」 – MarioTheHedgehog

回答

0

在VBA中,你可以試試下面的醜陋,但工作代碼:

Sub missing() 

Dim ya As Long, yb As Long, yc As Long, alast As Long, blast As Long 
Dim flag As Boolean 

yc = 2 
yb = 2 
flag = 0 
alast = Range("A65536").End(xlUp).Row 
blast = Range("B65536").End(xlUp).Row 

For ya = 2 To alast 
flag = 0 

Do While yb <= blast 
    If Range("A" & ya) = Range("B" & yb) Then flag = 1 
    yb = yb + 1 
    Loop 

    If flag = 0 Then 
     Range("C" & yc) = Range("A" & ya) 
     yc = yc + 1 
    End If 

    yb = 2 

Next ya 

End Sub