Array Formulas for Personal Functions

John McGraw

Board Regular
Joined
Feb 25, 2002
Messages
76
Can the entry of array formulas in cells work with your own self-written VBA functions?

I wrote a function that recieves a Range,
but when I try to utilize it with a conditional array,
example:
{=MYFUNCTION(IF(A1:A100=10,B1:B100))}

I get #VALUE. Am I doing something wrong, or is this just not allowed with homemade functions? I did press CTRL+Shift+Enter BTW.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Post your function and what you hope to accomplish with it and I'm sure that someone will be able to help you.

-rh
 
Upvote 0
On 2002-03-07 16:00, Russell Hauf wrote:
Post your function and what you hope to accomplish with it and I'm sure that someone will be able to help you.

-rh

I'm just expirementing, so my code is just
an average function:

----
Function MyAverage(DRange As Range) As Double

Dim R As Object
Dim Sum As Double
Dim Count As Integer

Count = 0: Sum = 0

For Each R In DRange
Sum = Sum + R.Value
Count = Count + 1
Next R

MyAverage = Sum / Count

End Function
----

Now, this works fine with if I just use it in normal formulas, but it returns "#VALUE!" if I try to use it in an array formula.

So, if column A = {1;1;2;2;1} and
B = {1;4;2;9;10}

I get the following results:

As Array Formulas
{=myaverage(IF(A1:A5=1,B1:B5))} = #VALUE!
{=AVERAGE(IF(A1:A5=1,B1:B5))} = 3
As Normal Formulas
=myaverage(B1:B5) = 5.2
=AVERAGE(B1:B5) = 5.2
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top