View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
JackRnl[_6_] JackRnl[_6_] is offline
external usenet poster
 
Posts: 1
Default transferring matrix to range


The OP indeed was "how to put a *matrix* (multiple array) to a range an
the info supplied by Ken did solve that.
But I also had a problem with an array consisting of a single column.
It was strange to me it didn't work transferring the data for a singl
column but *did* work with a multiple columns. I just didn't see th
fundamental difference so I didn't mention "single column" (allthoug
the code I supplied later
For i = 1 To NumLines
arrResults(i) = i * 4
Next i

did indicate I was talking about a single column at that time)
Sorry Alan for not being that clear and wasting your time.

Thanks to the info supplied I searched the internet for the 546
limitation and found some remarkable things.

First I found this very intersting article http://tinyurl.com/qt9xt
and now I will be using
Function TransposeArray(ByRef arr)
'// Application.Transpose has a limit of 5461 items (In case NO
XL2002 and the later version).
'// Causing "Run-time Error 13 Type mismatch"
'// But Excel WILL accept a multi dimensional array of the righ
size, so convert it
'// http://support.microsoft.com/kb/177991/
ReDim buf(LBound(arr) To UBound(arr), LBound(arr) To LBound(arr))
For i = LBound(buf) To UBound(buf)
buf(i, LBound(buf)) = arr(i)
Next i
TransposeArray = buf '// A multi column array will be returned
End Function

and *MyRange = TransposeArray(MyArray)* to get values into the rang
for a singlecolumn range and I think I will expand the function to tak
care of multicolumn arrays as well in order to use the *same* code fo
*any* filling of a range with values from an array and forget about
rng = multi_arr 'for range with multiple columns
rng = application.transpose 'for range with single column and "few
elements
rng = TransposeArray 'for range with single column an
"many" elements

I als saw this code
Sub Does_Work_Xl2000()
Dim rng As Variant, arr As Variant
Dim Lst As Long
Lst = 10000
rng = Evaluate("transpose(row(1:" & Lst & ")/row(1:" & Lst & "))")
arr = rng
Debug.Print UBound(arr) & ": " & arr(UBound(arr))
End Sub

but I didn't have a problem assigning values from a large single colum
range into an array and I didn't see the need for something similar (
TransposeRange) . But maybe I made a mistake.

Anyway it seems as Microsoft did solve the problem for Excel version
after XL2000 at the place where it should be : in *its* code
So I would like to know how can test for easily and fast for wha
version I'm using (will Application.Version be needed -- returning
*string* instead of a "value* so testing like *if Application.versio
"9.0" then* will fail for later versions) ro change TransposeArra

accordingly.
I also would like to know if I need to use the following code t
findout if an array has one or several dimension

bJustone=true
on error goto JustOne
SecondDimension=ubound(rng,2)
bJustOne=False
JustOne:

One further remark, I use *ByRef* in my TransposeArray function instea
of *ByVal* I've seen in other code, would you please tell if I *need* t
use ByVal


Thanks for all comments, they helped a lot and made my code run correc
and faster (from 200 seconds down to 10

--
JackRn
-----------------------------------------------------------------------
JackRnl's Profile: http://www.excelforum.com/member.php...fo&userid=3717
View this thread: http://www.excelforum.com/showthread.php?threadid=56888