find不是价值的第一个瑕疵

在一个典型的find函数中find一个包含“DID”testing的单元格,代码看起来像这样

Set cell = Selection.Find(What:="DID", After:=ActiveCell, _ LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 

但是,如果我正在尝试查找除“DID”以外的其他任何内容的第一个实例呢? 我尝试了以下,但似乎并没有工作。

 Set cell = Selection.Find(What <> "DID", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) 

你可以一起使用.Find.FindNext 。 这是你想要的吗?

 Sub Sample() Dim aCell As Range, bCell As Range Set aCell = Cells.Find(What:="*", LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) If Not aCell Is Nothing Then Set bCell = aCell If aCell.Value <> "DID" Then MsgBox aCell.Address Exit Sub End If Do Set aCell = Cells.FindNext(After:=aCell) If Not aCell Is Nothing Then If aCell.Address = bCell.Address Then Exit Do If aCell.Value <> "DID" Then MsgBox aCell.Address Exit Do End If End If Loop End If End Sub