查找其他列中未find的号码

我有这个excel公式,它查找在其他列中找不到的项目,并根据结果写入yes或no。 我怎样才能做到这一点,但在Excel中使用VBA?

=IFERROR(IF(MATCH(B2,$A:$A,0),"yes",),"no") 

我是新的VBA和Excel中,任何帮助表示赞赏。

以下代码使用Match函数比较列B中的值和列A中的值,并在列C中写入结果(是或否):

 Sub CompareColumns() Dim aLastRow As Long Dim bLastRow As Long Dim i As Long Dim result As Variant aLastRow = ThisWorkbook.ActiveSheet.Range("A1000").End(xlUp).Row bLastRow = ThisWorkbook.ActiveSheet.Range("B1000").End(xlUp).Row For i = 1 To bLastRow result = Application.Match(ThisWorkbook.ActiveSheet.Range("B" & i).Value, ThisWorkbook.ActiveSheet.Range("A1:A" & aLastRow), 0) If IsError(result) Then ThisWorkbook.ActiveSheet.Range("C" & i).Value = "No" Else ThisWorkbook.ActiveSheet.Range("C" & i).Value = "Yes" End If Next i End Sub 

考虑:

 Sub dural() Dim a As Range, b As Range Set a = Range("A:A") Set b = Range("B2") If Application.WorksheetFunction.CountIf(a, b) > 0 Then MsgBox "yes" Else MsgBox "no" End If End Sub