LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Assign Range passed to fuction to an array

Michael,

Your function simplified

=testfunc2(A1:A10)

Function testfunc2(rng As Range) As Double
Dim r As Variant
Dim arr As Variant
Dim x As Integer

For x = 1 To rng.Count
Debug.Print rng.Item(x).Value
Debug.Print rng.Item(x).Address
Next x

End Function


Mike

"Michael" wrote:

On Mar 3, 2:00 pm, Michael wrote:
I am looking for an example of how to pass a function a range and
assign it to an array so I can access the values with an index number.
For some reason I cant get this to work.


Forgot to indclude example

Function testfunc2(rng As Range)
Dim r As Variant
Dim arr As Variant
Dim x As Integer

'arr = rng

'assign range values to array
For Each r In rng
arr(x) = r.Value
x = x + 1
Next

'list array values
For x = LBound(arr) To UBound(arr)
Debug.Print arr(x).Value
Next x

testfunc2 = "test"
End Function

 
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
Assign a 2D array of constant values to a range dodgo Excel Programming 4 October 19th 06 04:46 AM
Excel 2003. Assign array to range Jorge Vinuales Excel Programming 2 May 2nd 06 06:06 PM
Translate range name passed as string to a custom function to range addresses! agarwaldvk[_25_] Excel Programming 3 September 7th 04 12:47 PM
Error Converting Passed Range into Array in VBA for Excel Alan Beban[_2_] Excel Programming 0 September 1st 04 04:56 PM
Error Converting Passed Range into Array in VBA for Excel Dave Peterson[_3_] Excel Programming 0 September 1st 04 01:17 AM


All times are GMT +1. The time now is 09:19 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"