*.Find()

  • Thread starter Thread starter FARAZ QURESHI
  • Start date Start date
F

FARAZ QURESHI

I am trying to design a UDF to return "Found" if a piece of string is present
in a text, either manually inserted or by a cell address. What's wrong with
the following code:

Function FndTxt(aax As String, bbx As String) ', bbx As String)
If aax.Text = aax.Find(bbx.Text, , , , , , True).Text Then
FndTxt = "Found"
Else
FndTxt = "Not Found"
End If
End Function
 
You declared aax and bbx as Strings... Strings do not have properties or
methods, so you can't use aax.Find or bbx.Text. Since they are Strings, you
will have to use String functions on them. Try it this way...

Function FndTxt(aax As String, bbx As String)
If InStr(aax, bbx) > 0 Then
FndTxt = "Found"
Else
FndTxt = "Not Found"
End If
End Function
 
Find is worksheetfunction..Try with INSTR() as below

A1 = Faraz
=fndtxt(A1,"x")

Function FndTxt(aax As String, bbx As String) As String
FndTxt = "Not found"
If InStr(1, aax, bbx, vbTextCompare) > 0 Then FndTxt = "Found"
End Function
 
Thanx Rick!

XClent!

Rick Rothstein said:
You declared aax and bbx as Strings... Strings do not have properties or
methods, so you can't use aax.Find or bbx.Text. Since they are Strings, you
will have to use String functions on them. Try it this way...

Function FndTxt(aax As String, bbx As String)
If InStr(aax, bbx) > 0 Then
FndTxt = "Found"
Else
FndTxt = "Not Found"
End If
End Function
 

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

Back
Top