.Find doesn't find matching cell value in first cell of range

Prevost

Board Regular
Joined
Jan 23, 2014
Messages
198
Hi There. I am using the .find function to find a value in a range (single column) and return the row number where that value first occurs. When my range is Cells(2,1) to Cells(40,1) and my value that I am trying to find is in Cell(2,1) (the value is actually in first 10 cells) the message box returns 3, not 2. Is this something inherent to Excel's find function, that it will not find the a matching value if it is in the first cell of a range or (more likely) what am i doing wrong? Thanks!

Code:
Sub testyme()

    Dim findtest As Range
    
        Set findtest = Range(Cells(2, 1), Cells(40, 1)).Find(what:="8E00002", lookat:=xlWhole)
        MsgBox (findtest.Row)

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
The cell after which you want the search to begin. This corresponds to the position of the active cell when a search is done from the user interface. Notice that After must be a single cell in the range. Remember that the search begins after this cell; the specified cell isn’t searched until the method wraps back around to this cell. If you do no specify this argument, the search starts after the cell in the upper-left corner of the range.

There is an after argument that is optional.

Code:
[COLOR=#454545][FONT=Segoe UI].[/FONT][/COLOR][COLOR=#454545][FONT=Segoe UI]Find[/FONT][/COLOR][COLOR=#454545][FONT=Segoe UI]([/FONT][/COLOR][B][I]What[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]After[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]LookIn[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]LookAt[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]SearchOrder[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]SearchDirection[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]MatchCase[/I][/B][COLOR=#454545][FONT=Segoe UI], [/FONT][/COLOR][B][I]MatchByte[/I][/B][COLOR=#454545][FONT=Segoe UI],[/FONT][/COLOR][B][I]SearchFormat[/I][/B][COLOR=#454545][FONT=Segoe UI])[/FONT][/COLOR]
 
Upvote 0
Thanks. Then how do you start searching at the top left cell of the range? It says if it's omitted, the search begins after the cell in the top left corner, but if you specify a cell in the range, it starts after that cell. Do you have to specify the last cell in the range?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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