Range Find

G

greg

I am using the Find method of Range.
Do you have to find whole strings of the cell?
I am sending in a filename. But my cell contains full path. and it is not
finding the cell.
For example:

Cell:
C:\foo\foo\foo\myfile.doc

and my code is this:
Set objFind = objSheet.Range(strRange).Find(what:=Trim$("myfile.doc"),
LookIn:= _
xlFormulas, lookat:=xlWhole, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False)

Do you need to find full strings?
 
J

JE McGimpsey

Take a look in VBA Help for the Find function. Specifically, the
"LookAt" argument...
 
K

Kenneth Hobson

Sub t()
Dim objFind As Range
Dim objSheet As Worksheet
Dim strRange As String

[a1] = "whatever"
[a2] = "something else"
[a3] = "C:\foo\foo\foo\myfile.doc"
[a4] = "end"
strRange = "A:A"
Set objSheet = ActiveSheet

Set objFind = objSheet.Range(strRange).Find(what:="*myfile.doc", _
LookIn:=xlFormulas, lookat:=xlWhole, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)

If Not objFind Is Nothing Then MsgBox objFind.Address
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top