Code line meaning?

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,984
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.
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
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..)
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,754
Messages
5,638,170
Members
417,011
Latest member
Amaden95

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
Top