Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Help with UDF Function

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with UDF Function

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)


"Carim" wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Help with UDF Function

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


"Carim" wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Help with UDF Function

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.

--
When sending mail, use address arvil<attarkon.ee
Arvi Laanemets


"Carim" wrote in message
oups.com...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Help with UDF Function

Thanks Bob,

I was totally stuck ... !!!

Cheers



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with UDF Function

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.

--
Regards,
Tom Ogilvy


"Carim" wrote in message
oups.com...
Thanks Bob,

I was totally stuck ... !!!

Cheers



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with UDF Function

One day, I'll upgrade <g


"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy


"Carim" wrote in message
oups.com...
Thanks Bob,

I was totally stuck ... !!!

Cheers





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"