Help with UDF Function

  • Thread starter Thread starter Carim
  • Start date Start date
C

Carim

Hi,

Below is my code, which as a macro, works fine ...
But transposed into a Function, it does not work ...

Function PLE(Rng As Range) As Variant

Dim i, j As Integer
i = Reng.Value
j = Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
PLE = Application.WorksheetFunction.Sum(Range(Cells(i, j - 2),
Cells(i, j)))

End Function

What is wrong ?
TIA
 
I don't think Find works in a UDF, it fails on the Find itself.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
use
OPTION EXPLICIT
and you'd not have needed to ask

i = Rng.Value

Under Tools/Options check Require Option Declaration
then Excel will add this for you
 
Hi

Search activates the cell it finds the searched value in - it means the
cursor position is changed, what means that a real change is made in
workbook. Functions in Excel aren't allowed to change anything - they only
can return a result. Use Do...While or Do...Until cycle to read data from
cells in range (not to select cells!), until the condition is true, instead.
 
Just to add some information, Dave Peterson has reported that the FIND
method works in a UDF in xl2002 and later. In earlier versions, it does not
as Bob has stated.
 
One day, I'll upgrade <g>


Tom Ogilvy said:
Just to add some information, Dave Peterson has reported that the FIND
method works in a UDF in xl2002 and later. In earlier versions, it does not
as Bob has stated.
 

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