Range.Find-Methode Search complete sheet

DocAElstein

Banned user
Joined
May 24, 2014
Messages
1,336
Hi,
. Am I right in assuming that in the Range.Find-Methode, for either the optional argument xlNext or xlPrevious, the worksheet search goes through one complete sheet cycle? That is to say, that the search starts and stops at the same place.
. So for example with argument xlNext. – If the search starts somewhere in the middle of the sheet, then once it reaches the End of the sheet, it jumps back to the start and continues again in the forward direction with the search until it reaches the start point.
. Similarly for the case of the optional argument xlPrevious. - A search starting somewhere in the middle of the sheet would look backwards and when reaching the first cell, it jumps to the last cell and looks backwards until it reaches the start point.

. That ties up with my experimenting but I have not managed to find that stated anywhere yet.

. So a good way to find the Last cell with a value or formula in it would be as in the following code, kindly supplied to me by shg.
(Thisallows for different sheet sizes with different XL versions etc.)

Code:
Function Last(wks As Worksheet) As Range
 
    Set Last = wks.Cells.Find(What:="*", _
                              After:=wks.Cells(1, 1), _
                              Lookat:=xlPart, _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious)
 
    End Function

Thanks
Alan Elston.
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,
. Am I right in assuming that in the Range.Find-Methode, for either the optional argument xlNext or xlPrevious, the worksheet search goes through one complete sheet cycle? That is to say, that the search starts and stops at the same place.
. So for example with argument xlNext. – If the search starts somewhere in the middle of the sheet, then once it reaches the End of the sheet, it jumps back to the start and continues again in the forward direction with the search until it reaches the start point.
. Similarly for the case of the optional argument xlPrevious. - A search starting somewhere in the middle of the sheet would look backwards and when reaching the first cell, it jumps to the last cell and looks backwards until it reaches the start point.

. That ties up with my experimenting but I have not managed to find that stated anywhere yet.

. So a good way to find the Last cell with a value or formula in it would be as in the following code, kindly supplied to me by shg.
(Thisallows for different sheet sizes with different XL versions etc.)

Code:
Function Last(wks As Worksheet) As Range
 
    Set Last = wks.Cells.Find(What:="*", _
                              After:=wks.Cells(1, 1), _
                              Lookat:=xlPart, _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious)
 
    End Function

Thanks
Alan Elston.

Yes, yes and yes.
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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