Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Marco Exits without error

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 exits without asking if I want to save ch Excel Discussion (Misc queries) 2 November 25th 09 12:45 AM
Prompt msg if the worksheet already exits Dee New Users to Excel 2 November 7th 08 05:11 PM
Find if value exits in array Glynn Excel Worksheet Functions 6 September 5th 08 08:46 PM
Closing a workbook, exits Excel 2007 too Sonya Torian Excel Discussion (Misc queries) 0 March 12th 08 02:37 PM
Excel Exits on File Close with Outlook Erin Searfoss Excel Discussion (Misc queries) 1 January 16th 05 09:43 PM


All times are GMT +1. The time now is 07:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"