View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default Marco Exits without error

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"
wrote in message
...
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