Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help with UDF Function
Thanks Bob,
I was totally stuck ... !!! Cheers |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
copy of excel file not showing formulal/function in the function b | Excel Discussion (Misc queries) | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Offset function with nested match function not finding host ss. | Excel Worksheet Functions | |||
Adding a custom function to the default excel function list | Excel Programming | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |