Return to index: [Subject] [Thread] [Date] [Author]

Re: Return and array from VBA to Excel

[Subject Prev][Subject Next][Thread Prev][Thread Next]
Jake,

array_data is a dimensioned variable. Use appropriate
dimension for array_data in the DIM Statement.

Few more observations:

A Function procedure will yield only one value. You
cannot create an array with it. 

The program line "array_test = array_data" is
incorrect because array_data is a dimensioned
quantity. For example, it must be something like,
array_data(k,l)

If you want to create an array, use a SUB procedure

Rajendran
--- Jake Watson <jwatson(--nospam--at)utahisp.com> wrote:
> I am trying to get VBA for Excel 2003 to return an
> array from a custom
> function to a worksheet.  Following is some useless
> sample code.  Does
> anyone know how to get the array out of VBA and into
> a worksheet?
> 
>  
> 
> VBA Code:
> 
>  
> 
> Function array_test(n_rows, n_cols)
> 
> Dim array_data As Variant
> 
>     For i = 1 To n_rows
> 
>         For j = 1 To n_cols
> 
>             array_data(i, j) = i + j / 100
> 
>             Next j
> 
>         Next i
> 
>     array_test = array_data
> 
> End Function
> 
>  
> 
>  
> 
> Then I enter enter {=array_test(5,5)} in cell A1 and
> get "#VALUE!".  Any
> suggestions would be appreciated.
> 
>  
> 
> Jake Watson, P.E.
> 
> Salt Lake City, UT
> 
>  
> 
>  
> 
> 


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

******* ****** ******* ******** ******* ******* ******* ***
*   Read list FAQ at: http://www.seaint.org/list_FAQ.asp
* 
*   This email was sent to you via Structural Engineers 
*   Association of Southern California (SEAOSC) server. To 
*   subscribe (no fee) or UnSubscribe, please go to:
*
*   http://www.seaint.org/sealist1.asp
*
*   Questions to seaint-ad(--nospam--at)seaint.org. Remember, any email you 
*   send to the list is public domain and may be re-posted 
*   without your permission. Make sure you visit our web 
*   site at: http://www.seaint.org 
******* ****** ****** ****** ******* ****** ****** ********