Excel VBA检查值是否在范围内

我有两个范围应该是相同的(虽然他们可能被sorting不同)。 我试图findrangeA中不在rangeB中的任何值。

我可以find一些例子,显示值是否在一个范围内匹配,但如果不是,则可以努力find任何东西。

到目前为止我有:

Sub Compare2() Dim test1, cell As Range Dim FoundRange As Range Set test1 = Sheets("Names").Range("A1:A5") For Each cell In test1 Set FoundRange = Sheets("Queue & Status").Range("A1:A200").Find(what:=test1, LookIn:=xlFormulas, lookat:=xlWhole) If FoundRange Is Nothing Then MsgBox (cell & " not found") End If Next cell End Sub 

但是,它显示所有的值都不匹配。

尝试这个

 Sub Compare2() Dim test1 As Range Dim lookIn As Range Dim c As Range Dim FoundRange As Range Set test1 = Sheets("Names").Range("A1:A5") Set lookIn = Sheets("Queue & Status").Range("A1:A200") For Each c In test1 Set FoundRange = lookIn.Find(what:=c.Value, lookIn:=xlFormulas, lookat:=xlWhole) If FoundRange Is Nothing Then MsgBox (c.Value & " not found") End If Next c End Sub 

什么:= test1应该是什么:=单元格(甚至什么:= cell.value)