Macro - Find Function not working

G

Greg T

When I used the FIND function in a macro I get an "Compile Error" function
not defined". It works fine when I use it in a cell in a worksheet. Is
there a seperate Reference that needs to be added?
 
P

Per Jessen

Hi

If it is the worksheetfunction find you want to use, you have to use:

WorksheetFunction.Find(...)

If this does not help, post your code for further help.

Regards,
Per
 
G

Gary''s Student

Find means two different thing:

1. a function
2. a method

In a worksheet cell:

=FIND("happiness",A1)

will look for "happiness" in A1 and return a number telling you where it
begins. To do this in VBA, use:

Sub dural()
Dim A1 As Range
Set A1 = Range("A1")
x = Application.WorksheetFunction.Find("happiness", A1)
End Sub
 
D

Dave Peterson

If you're looking to find something in a string, then use VBA's built-in Instr()
function.

No need to use application.find() or worksheetfunction.find().
 

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