Default300
Board Regular
- Joined
- Jul 13, 2009
- Messages
- 83
Full Code can be posted if required.
It is derived from an apparently functional Find / Find Next Do / Loop While routine that I found online.
This is the close of the Loop. The Loop should be exited if either there are no more cells matching search criteria (first condition); or if the range found matches the first range found (second condition), indicating that the Find operation has looped back to start.
Problem
I get:
Run-time error '91':
Object variable or With block variable not set
On the following line of code:
When: rngRange Is Nothing.
Troubleshooting
I presume the problem is that the second condition (And rngRange.Address <> strRangeString), can't be resolved since rngRange Is Nothing.
Is there a better way to code this?
Proposed Solution (1)
Would the following code work? Or does first condition need the double negative: Not Range Is Nothing?
NB: As well as changing And to Or; While to Until; and Negative conditions to Positive; I'm also proposing to store first range found as a Range, not an address String:
Proposed Solution (2)
Alternatively, should I check for the conditions, using 2 If Statements, as follows:
Or some combination of the three? Thanks.
It is derived from an apparently functional Find / Find Next Do / Loop While routine that I found online.
This is the close of the Loop. The Loop should be exited if either there are no more cells matching search criteria (first condition); or if the range found matches the first range found (second condition), indicating that the Find operation has looped back to start.
Problem
I get:
Run-time error '91':
Object variable or With block variable not set
On the following line of code:
Code:
[FONT=Courier New]Loop While Not rngRange Is Nothing _
And rngRange.Address <> strRangeString[/FONT]
Troubleshooting
I presume the problem is that the second condition (And rngRange.Address <> strRangeString), can't be resolved since rngRange Is Nothing.
Is there a better way to code this?
Proposed Solution (1)
Would the following code work? Or does first condition need the double negative: Not Range Is Nothing?
NB: As well as changing And to Or; While to Until; and Negative conditions to Positive; I'm also proposing to store first range found as a Range, not an address String:
Code:
[FONT=Courier New]Loop Until rngRange Is Nothing _
Or rngRange = rngRangeFirstFound[/FONT]
Alternatively, should I check for the conditions, using 2 If Statements, as follows:
Code:
[FONT=Courier New]If [/FONT][FONT=Courier New]Not rngRange Is Nothing Then[/FONT]
[FONT=Courier New] If [/FONT][FONT=Courier New]rngRange.Address <> [/FONT][FONT=Courier New]strRangeString[/FONT][FONT=Courier New] Then
Exit Do
[/FONT][FONT=Courier New]
Loop While Not rngRange Is Nothing[/FONT]
Last edited: