最も近いのは、検索を並行して(効果的に)実行し、MIN()
見つかった最初のセルを選択するために使用することだと思います。
Sub FindingNemor()
Dim rngFoo As Range
Dim rngBar As Range
Set rngFoo = Cells.Find(What:="foo", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
Set rngBar = Cells.Find(What:="bar", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not rngFoo Is Nothing And Not rngBar Is Nothing Then
Range("A1").Cells(Application.Min(rngFoo.Row, rngBar.Row)).Select
End If
End Sub
rngFoo または rngBar の 1 つだけが Nothing の場合は、追加のチェックが必要です。
-nessのチェックを追加Nothing
すると、少し面倒になります。
Sub FindingNemor()
Dim rngFoo As Range
Dim rngBar As Range
Set rngFoo = Cells.Find(What:="foo", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
Set rngBar = Cells.Find(What:="bar", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not rngFoo Is Nothing And Not rngBar Is Nothing Then
Range("A1").Cells(Application.Min(rngFoo.Row, rngBar.Row)).Select
ElseIf rngFoo Is Nothing Then
If rngBar Is Nothing Then
MsgBox "Neither found."
Else
Range("A1").Cells(rngBar.Row).Select
End If
Else
Range("A1").Cells(rngFoo.Row).Select
End If
End Sub