Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Index is not in range

Hi
I have code:
Public Sub Main()

Dim P(1 To 2, 1 To 2) As Variant
Dim X(1 To 2, 1 To 2) As Variant
Dim r() As Variant

P(1, 1) = 3
X(1, 1) = 4
r = Test(P, X)

End Sub

Function Test(ByRef Arra1y As Variant, ByRef Arra2y As Variant) As
Variant

Dim ResultArray(1 to 2,1 to 2) As Variant


ResultArray(1)(1) = Arra2y(1)(1) + Arra1y(1)(1)

End Function

I have always error:Index is not in range. How can I return array in
this example?

Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Index is not in range

I'm not sure I understand, but maybe...

Option Explicit
Public Sub Main()
Dim P(1 To 2, 1 To 2) As Variant
Dim X(1 To 2, 1 To 2) As Variant
Dim r As Variant

P(1, 1) = 3
X(1, 1) = 4
r = Test(P, X)
End Sub
Function Test(ByRef Arra1y As Variant, ByRef Arra2y As Variant) As Variant
Dim ResultArray(1 To 2, 1 To 2) As Variant
ResultArray(1, 1) = Arra2y(1, 1) + Arra1y(1, 1)
End Function



leo wrote:

Hi
I have code:
Public Sub Main()

Dim P(1 To 2, 1 To 2) As Variant
Dim X(1 To 2, 1 To 2) As Variant
Dim r() As Variant

P(1, 1) = 3
X(1, 1) = 4
r = Test(P, X)

End Sub

Function Test(ByRef Arra1y As Variant, ByRef Arra2y As Variant) As
Variant

Dim ResultArray(1 to 2,1 to 2) As Variant

ResultArray(1)(1) = Arra2y(1)(1) + Arra1y(1)(1)

End Function

I have always error:Index is not in range. How can I return array in
this example?

Regards


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default Index is not in range

On Sat, 14 Mar 2009 11:02:41 -0700 (PDT), leo
wrote:

Hi
I have code:
Public Sub Main()

Dim P(1 To 2, 1 To 2) As Variant
Dim X(1 To 2, 1 To 2) As Variant
Dim r() As Variant

P(1, 1) = 3
X(1, 1) = 4
r = Test(P, X)

End Sub

Function Test(ByRef Arra1y As Variant, ByRef Arra2y As Variant) As
Variant

Dim ResultArray(1 to 2,1 to 2) As Variant


ResultArray(1)(1) = Arra2y(1)(1) + Arra1y(1)(1)

End Function

I have always error:Index is not in range. How can I return array in
this example?

Regards



Try changing (1)(1) to (1,1) in three places

and add

Test = ResultArray

at the end of you function, just before End Function

Hope this helps / Lars-Åke
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
INDEX using range BJ Excel Worksheet Functions 2 July 25th 08 10:43 PM
Index by Range BC Excel Worksheet Functions 4 June 29th 06 12:39 AM
Use index to get range for dget to use Adella[_2_] Excel Programming 2 November 21st 05 07:24 PM
Use Index to get range Adella Excel Worksheet Functions 4 November 17th 05 05:56 PM
index to a range of cells Frank Kabel Excel Worksheet Functions 0 October 27th 04 05:39 PM


All times are GMT +1. The time now is 09:05 PM.

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"