The reason he gives only the first match is a mistake. See Link (SECTION 5) below.
. , .
, - ( )
.FindNext , . .
, Sheet1:
A1 → Colt
A2 → Holt
A3 → Dolt
A4 → Hello
B1 → olt
, , $A$1:$A$3
Sub Test()
Sample Sheets("Sheet1").Range("B1"), Sheets("Sheet1").Range("A1:A4")
End Sub
Sub Sample(FirstRange As Range, ListRange As Range)
Dim aCell As Range, bCell As Range, oRange As Range
Dim ExitLoop As Boolean
Set oRange = ListRange.Find(what:=FirstRange.Value, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
ExitLoop = False
If Not oRange Is Nothing Then
Set bCell = oRange: Set aCell = oRange
Do While ExitLoop = False
Set oRange = ListRange.FindNext(After:=oRange)
If Not oRange Is Nothing Then
If oRange.Address = bCell.Address Then Exit Do
Set aCell = Union(aCell, oRange)
Else
ExitLoop = True
End If
Loop
MsgBox aCell.Address
Else
MsgBox "Not Found"
End If
End Sub
, , (Say in Cell C1) =FindRange(A1,A1:A5)
1-
, , , , - $A $2!!!
Function FindRange(FirstRange As Range, ListRange As Range) As String
Dim aCell As Range, bCell As Range, oRange As Range
Dim ExitLoop As Boolean
Set oRange = ListRange.Find(what:=FirstRange.Value, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
ExitLoop = False
If Not oRange Is Nothing Then
Set bCell = oRange: Set aCell = oRange
Do While ExitLoop = False
Set oRange = ListRange.FindNext(After:=oRange)
If Not oRange Is Nothing Then
If oRange.Address = bCell.Address Then Exit Do
Set aCell = Union(aCell, oRange)
Else
ExitLoop = True
End If
Loop
FindRange = aCell.Address
Else
FindRange = "Not Found"
End If
End Function
.
.FindNext .Find, ($ A $1: $A $3). . , :
Function FindRange(FirstRange As Range, ListRange As Range) As String
Dim aCell As Range, bCell As Range, oRange As Range
Dim ExitLoop As Boolean
Set oRange = ListRange.Find(what:=FirstRange.Value, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
ExitLoop = False
If Not oRange Is Nothing Then
Set bCell = oRange: Set aCell = oRange
Do While ExitLoop = False
Set oRange = ListRange.Find(what:=FirstRange.Value, After:=oRange, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not oRange Is Nothing Then
If oRange.Address = bCell.Address Then Exit Do
Set aCell = Union(aCell, oRange)
Else
ExitLoop = True
End If
Loop
FindRange = aCell.Address
Else
FindRange = "Not Found"
End If
End Function