Code line meaning?

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
The 3rd line below has me confused. Maybe I'm taking it to literally by thinking that it is saying: Start looking AFTER all the cells in the Range defined by the With Statement that it is a part of. This doesn't make sense.
Can someone interpret the true meaning of the line?


For i = LBound(MyArr) To UBound(MyArr)
Set Rng = .Find(What:=MyArr(i), _
After:=.Cells(.Cells.Count), _
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
That is what its saying.
.Find doesn't stop looking at the end of the range, it loops back to the start of the range.
Code:
With myRange
    .Find what:="foo",After:=.Range("A1")
End With
will find the first cell containing "foo" after the first cell in the range
Code:
With myRange
    .Find what:="foo",After:=.Cells(.Cells.Count)
End With
will find the first cell in the range that contains "foo", even if that cell is the first in the range.
 
Upvote 0
Andrew:
It starts after the cell at bottom right of the sheet, ie at A1.

Then it starts after IV65536 (in say xl2003)? Does it loop back up to A1 on the same sheet, or go to the next sheet (in sequence)? (anything is possible..)
 
Upvote 0
If you have selected "Workbook" in the "Within" option in the search options, then yes it will go to the next sheet first.

If you have selected "SHEET" in the Within options, then it will loop straight back to A1 on that sheet.

I'm pretty sure "Sheet" is the default selection. So unless you specify workbook, it will only look on the sheet.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top