LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Declare and array in a function

Your code worked fine for me both when called from another macro:

[demo'd from the immediate window)

? test(Range("A1:C6"))
13

and from the worksheet

=Test(A1:C6")
displayed 13

If you feed it a range with more than 20 rows or less than 5 rows you would
have a problem

--
Regards,
Tom Ogilvy


"Dave" wrote in message
...
I'm trying to declare an array from within a function, and then add to
that
array certain fields from a range I use as the input variable. For
example:

Function test(rng As Range)
valuesArr = rng
ReDim testArray(20) As String

For i = 1 To UBound(valuesArr)
testArray(i) = valuesArr(i, 1)
Next i
test = testArray(5)
End Function

So I want to add all values from within "rng" to "testArray()", and then
take the 5th element of testArray() and return it. I keep getting an
error
when I enter the function, any ideas?
Thanks.



 
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
Declare Variables in Array Mike H. Excel Discussion (Misc queries) 2 March 11th 09 12:33 PM
How do I declare a function whose output is an array? Schizoid Man[_2_] Excel Programming 5 May 24th 06 09:23 PM
Global array declare Souris Excel Programming 3 August 20th 05 11:38 AM
How to declare a dynamic array Peter Rooney Excel Discussion (Misc queries) 4 April 13th 05 01:25 PM
Declare an Array() ???? Andoni[_23_] Excel Programming 1 August 31st 04 07:12 PM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"