Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Passing array to a function

AAA=ExactMatch ( Guess(1,) )

The above does not work, needless to say.

ExactMatch is a function expecting to receive a single dimensional array

Guess is a 2-dimensional array. What I am attempting to do is pass the 1st
row of Guess to the function.

What is the correct syntax to do that, please? (Obviously, I can be more
explicit about what I am passing across, but I thought VBA would take care
of this for me.)

Thanks

Geoff



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing array to a function

There is no automatic way in VBA to do this.

Since you are using VBA in Excel, you can use the Excel Index function

Sub Tester2()
Dim myArray(1 To 6, 1 To 2)
For i = 1 To 6
For j = 1 To 2
myArray(i, j) = Chr(i * j + 64)
Next j
Next i
varr = Application.Index(myArray, 0, 2)
For i = LBound(varr) To UBound(varr)
Debug.Print i, varr(i, 1), myArray(i, 1), myArray(i, 2)
Next
End Sub


This returns the second column of a 2D array - but it returns it as 1 x
Number of rows, 1 x 1

--
Regards,
Tom Ogilvy



GB wrote in message
...
AAA=ExactMatch ( Guess(1,) )

The above does not work, needless to say.

ExactMatch is a function expecting to receive a single dimensional array

Guess is a 2-dimensional array. What I am attempting to do is pass the 1st
row of Guess to the function.

What is the correct syntax to do that, please? (Obviously, I can be more
explicit about what I am passing across, but I thought VBA would take care
of this for me.)

Thanks

Geoff





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Passing array to a function

Did you really mean first Row?

Sub testme()

Dim myArray As Variant
Dim myArray2 As Variant

'just some test data in a 9x2 array
myArray = ActiveSheet.Range("a1:b9").Value
myArray2 = Application.Index(myArray, 1, 0)

End Sub

Or did you mean the first column?

Sub testme()

Dim myArray As Variant
Dim myArray2 As Variant

'just some test data in a 9x2 array
myArray = ActiveSheet.Range("a1:b9").Value

myArray2 = Application.Transpose(Application.Index(myArray, 0, 1))

End Sub

Be aware that application.transpose and application.index fail for some versions
of excel when the number of elements exceeds 5461. (xl2002 has been changed to
support lots more.)

GB wrote:

AAA=ExactMatch ( Guess(1,) )

The above does not work, needless to say.

ExactMatch is a function expecting to receive a single dimensional array

Guess is a 2-dimensional array. What I am attempting to do is pass the 1st
row of Guess to the function.

What is the correct syntax to do that, please? (Obviously, I can be more
explicit about what I am passing across, but I thought VBA would take care
of this for me.)

Thanks

Geoff


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Passing array to a function

Thanks Tom and Dave. I guess I was looking for something that does not exist
in VBA.

I had not thought of using Application.Index, but I can see that that would
shorten my code.

Thanks again.

Geoff


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
Passing string as array variable (Pivot VBA) klingongardener Excel Discussion (Misc queries) 2 December 23rd 06 07:58 PM
Passing a row to a function dch3 Excel Worksheet Functions 2 July 31st 06 12:34 PM
Passing a WorkSheet from a Function??? Mac Lingo Excel Worksheet Functions 3 June 13th 06 08:29 AM
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 01:37 PM.

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"