Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Array Formula/UDF

If I have a user defined function, say, Add and I want to enter an array
formula such as =Add(A1:A3,B1:B3) in cells C1:C3, how should I code the
function Add? Everything I've tried returns a #VALUE error. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Array Formula/UDF

On 3 Iun, 10:47, AA2e72E wrote:

Maybe you can use a parameter array :

Function Add(ParamArray Target() As Variant)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Array Formula/UDF

The trick is to return an array of values: something like this
(but you would need to add error checking etc etc)

Public Function ADD(Range1 as range,Range2 as range) as variant
dim vOut() as variant
dim v1 as variant
dim v2 as variant
dim j as long

redim vOut(1 to application.caller.rows.count,1 to 1)
v1=range1.Value2
v2=Range2.value2
for j=1 to ubound(vOut)
vOut(j,1)=v1(j,1)+v2(j,1)
next j
ADD=vOut
End Function


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

"AA2e72E" wrote in message
...
If I have a user defined function, say, Add and I want to enter an array
formula such as =Add(A1:A3,B1:B3) in cells C1:C3, how should I code the
function Add? Everything I've tried returns a #VALUE error. Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Array Formula/UDF

Perfect.

Thanks Charles.

"Charles Williams" wrote:

The trick is to return an array of values: something like this
(but you would need to add error checking etc etc)

Public Function ADD(Range1 as range,Range2 as range) as variant
dim vOut() as variant
dim v1 as variant
dim v2 as variant
dim j as long

redim vOut(1 to application.caller.rows.count,1 to 1)
v1=range1.Value2
v2=Range2.value2
for j=1 to ubound(vOut)
vOut(j,1)=v1(j,1)+v2(j,1)
next j
ADD=vOut
End Function


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

"AA2e72E" wrote in message
...
If I have a user defined function, say, Add and I want to enter an array
formula such as =Add(A1:A3,B1:B3) in cells C1:C3, how should I code the
function Add? Everything I've tried returns a #VALUE error. Thanks.




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 02:05 AM.

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"