Marco Exits without error

  • Thread starter Thread starter jlclyde
  • Start date Start date
J

jlclyde

My code exits without a warning or going to completion. Any
thoughts? It seems to exit on the Loop While line.

Function Find_Range(Find_Item As Variant, Search_Range As Range, _
Optional LookIn As Variant, Optional LookAt As Variant, _
Optional MatchCase As Boolean) As Range


Dim firstAddress
Dim c As Range
If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole
If IsMissing(MatchCase) Then MatchCase = False

With Search_Range
Set c = .Find(What:=Find_Item, LookIn:=LookIn, LookAt:=LookAt,
_
SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=MatchCase, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Find_Range = c
firstAddress = c.Address
Do
Set Find_Range = Union(Find_Range, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

End Function

Thanks,
Jay
 
Try making the single line "Loop While Not c Is Nothing And c.Address <> firstAddress" into two
lines...
'---
If c is Nothing then Exit Do
Loop While c.Address <> firstAddress
'---
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(XL Companion add-in: compares, matches, counts, lists, finds, deletes...)



"jlclyde" <[email protected]>
wrote in message
news:cdace59e-60bf-4923-8a78-d6d48993220c@v37g2000yqb.googlegroups.com...
 
Back
Top