A
al007
Want to select cells in B1:B19 which have same value as in cell A1
Why macro below is not working - can anybody provide an alternative
Public Sub Select()
Dim rng As Range
Dim rngFound As Range
Dim rngOut As Range
Dim sStr As String
Dim firstAdd As String
Set rng = Range("A1")
sStr = rng.Value
Set rngFound = Range("B1:B19").Find _
(What:=sStr, _
After:=rng(1), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext)
If Not rngFound Is Nothing Then
firstAdd = rngFound.Address
Set rngOut = rngFound
End If
Do
Set rngFound = Range("B2:B19").FindNext(rngFound)
If Not rngFound Is Nothing Then
Set rngOut = Union(rngOut, rngFound)
End If
Loop While Not rngFound Is Nothing _
And rngFound.Address <> firstAdd
If Not rngOut Is Nothing Then rngOut.Select
End Sub
Why macro below is not working - can anybody provide an alternative
Public Sub Select()
Dim rng As Range
Dim rngFound As Range
Dim rngOut As Range
Dim sStr As String
Dim firstAdd As String
Set rng = Range("A1")
sStr = rng.Value
Set rngFound = Range("B1:B19").Find _
(What:=sStr, _
After:=rng(1), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext)
If Not rngFound Is Nothing Then
firstAdd = rngFound.Address
Set rngOut = rngFound
End If
Do
Set rngFound = Range("B2:B19").FindNext(rngFound)
If Not rngFound Is Nothing Then
Set rngOut = Union(rngOut, rngFound)
End If
Loop While Not rngFound Is Nothing _
And rngFound.Address <> firstAdd
If Not rngOut Is Nothing Then rngOut.Select
End Sub