![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 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. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Post your function and what you hope to accomplish with it and I'm sure that someone will be able to help you.
-rh |
|
|
|
|
|
#3 | |
|
Board Regular
Join Date: Feb 2002
Posts: 76
|
Quote:
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 |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|