vba - using activesheet find method

pelegk2

New Member
Joined
Dec 16, 2010
Messages
3
i used the code
Code:
 Sheet15.Activate
    Set R = ActiveSheet.Range("A1:A" & rows)
    intRow = R.Find(What:=lsfind, After:=R.Cells(1), LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Row
where lsfind is the string to find.
the problem is, that if i have a cell with a value "abcdsfgg"
and i look "abc", it gives me that value back, while i want to find is an exact match (a cell with only "abc")
how do i do that?
Thanks
Peleg
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Try

Rich (BB code):
Sheet15.Activate
    Set R = ActiveSheet.Range("A1:A" & Rows)
    intRow = R.Find(What:=lsfind, After:=R.Cells(1), LookIn:=xlFormulas, _
           LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Row
 

pelegk2

New Member
Joined
Dec 16, 2010
Messages
3
Thanks!
where can i read more about each of the option's of the find method, and there use?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
From the Help (Excel 2000)

Syntax
expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte)
expression Required. An expression that returns a Range object.
What Required Variant. The data to search for. Can be a string or any Microsoft Excel data type.
After Optional Variant. 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. Note 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 don’t specify this argument, the search starts after the cell in the upper-left corner of the range.
LookIn Optional Variant. Can be one of the following XlFindLookIn constants: xlFormulas, xlValues, or xlComments.
LookAt Optional Variant. Can be one of the following XlLookAt constants: xlPart or xlWhole.
SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByColumns or xlByRows.
SearchDirection Optional Variant. Can be one of the following XlSearchDirection constants: xlNext or xlPrevious. The default constant is xlNext.
MatchCase Optional Variant. True to make the search case sensitive. The default value is False.
MatchByte Optional Variant. Used only if you’ve selected or installed double-byte language support. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.
Remarks
The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.
You can use the FindNext and FindPrevious methods to repeat the search.
When the search reaches the end of the specified search range, it wraps around to the beginning of the range. To stop a search when this wraparound occurs, save the address of the first found cell, and then test each successive found-cell address against this saved address.
To find cells that match more complicated patterns, use a For Each...Next statement with the Like operator. For example, the following code searches for all cells in the range A1:C5 that use a font whose name starts with the letters "Cour". When Microsoft Excel finds a match, it changes the font to Times New Roman.

<code>For Each c In [A1:C5]
If c.Font.Name Like "Cour*" Then
c.Font.Name = "Times New Roman"
End If
Next
</code></pre>
 

Forum statistics

Threads
1,082,021
Messages
5,362,719
Members
400,686
Latest member
Aakash

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top