Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Michael,
This may do what you want. take this simple function below. Called with a range object you can refer to each cell of the range using .item. I've included 2 message boxes in the function to demonstrate the method but in practice these would be replaced with your code. =myvalue(A1:A10) Public Function MyValue(rng As Range) As Double Dim x As Long With rng For x = 1 To .Count MsgBox .Item(x).Address MsgBox .Item(x).Value Next x End With End Function Mike "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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Try this: MyArray = Array(Range("A1:A10").Value) Regards, Per "Michael" skrev i meddelelsen ... 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. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Assign a 2D array of constant values to a range | Excel Programming | |||
Excel 2003. Assign array to range | Excel Programming | |||
Translate range name passed as string to a custom function to range addresses! | Excel Programming | |||
Error Converting Passed Range into Array in VBA for Excel | Excel Programming | |||
Error Converting Passed Range into Array in VBA for Excel | Excel Programming |