我正在使用 Excel 2003 并尝试比较两列以在一列中查找不在另一列中的数据。
例如:
在 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