Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can I use a UDF in an array formula?

Hi all,

I wrote a small UDF which returns 0 or 1 depending on whether the
input cell meets certain criteria. It's something like

MyFunction(InputCell as double, Criteria1, Criteria2) as Integer

where the inputs and the outputs are single values, not arrays.

Is there a way to use it in an array formula?

For example, I have a named range called "bal". I tried entering the
array formula

{sum( 1*( MyFunction(bal,Criteria1,Criteria2)) )}

to count how many records meet my criteria, but it didn't work.

Any suggestion would be more than welcome!

Thanks a lot!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Can I use a UDF in an array formula?

Hi Santa,

You need to make your function return an array of the same size as the
InputRange:

Function MyFunction(InRange As Range) As Variant
Dim vArr As Variant
Dim j As Long
Dim k As Long

vArr = InRange.Value2

If VarType(vArr) = vbArray Then
For j = LBound(vArr) To UBound(vArr)
For k = LBound(vArr, 2) To UBound(vArr, 2)
If IsNumeric(vArr(j, k)) Then
vArr(j, k) = Abs(vArr(j, k))
End If
Next k
Next j
MyFunction = vArr
Else
MyFunction = Abs(vArr)
End If
End Function

regards
Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"SantaClaus" wrote in message
...
Hi all,

I wrote a small UDF which returns 0 or 1 depending on whether the
input cell meets certain criteria. It's something like

MyFunction(InputCell as double, Criteria1, Criteria2) as Integer

where the inputs and the outputs are single values, not arrays.

Is there a way to use it in an array formula?

For example, I have a named range called "bal". I tried entering the
array formula

{sum( 1*( MyFunction(bal,Criteria1,Criteria2)) )}

to count how many records meet my criteria, but it didn't work.

Any suggestion would be more than welcome!

Thanks a lot!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can I use a UDF in an array formula?

On 24 Apr, 12:39, "Charles Williams"
wrote:
Hi Santa,

You need to make your function return an array of the same size as the
InputRange:


Thanks a lot, that's very helpful!
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
Array formula SUMIF with 2D sum_range array Rich_84 Excel Worksheet Functions 3 April 3rd 09 10:46 PM
Array formula: how to join 2 ranges together to form one array? Rich_84 Excel Worksheet Functions 2 April 1st 09 06:38 PM
Find specific value in array of array formula DzednConfsd Excel Worksheet Functions 2 January 13th 09 06:19 AM
copy one array formula to an array range guedj54 Excel Programming 2 October 29th 06 07:38 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Excel Programming 0 July 27th 05 03:59 PM


All times are GMT +1. The time now is 03:20 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"