2-dim array into sheet

F

fabalicious

Hi ya!

Do you know a way to "paste" a 2-dimensional array (calculated in
macro) into a sheet (where one dimension will be rows and another on
columns, obviously...) ?

Help highly appreciated,

Fabaliciou
 
T

Tushar Mehta

Use something like the tested:

Option Explicit

Function DimensionSize(Arr, Optional whatDim As Integer = 1)
On Error Resume Next
DimensionSize = UBound(Arr, whatDim) - LBound(Arr, whatDim) + 1
End Function
Sub transferDataToXL()
Dim SomeArr(2 To 21, 3 To 12) As Double, _
i As Integer, j As Integer
For i = LBound(SomeArr, 1) To UBound(SomeArr, 1)
For j = LBound(SomeArr, 2) To UBound(SomeArr, 2)
SomeArr(i, j) = i / j
Next j
Next i
Range("a1").Resize( _
DimensionSize(SomeArr, 1), DimensionSize(SomeArr, 2)).Value = _
SomeArr
End Sub

I will leave it up to you to figure out what portions of the above code
were needed for testing and what do the actual work. ;-)



--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2004
 
A

Alan Beban

fabalicious said:
Hi ya!

Do you know a way to "paste" a 2-dimensional array (calculated in a
macro) into a sheet (where one dimension will be rows and another one
columns, obviously...) ?

Range("A11").Resize(UBound(TwoDarray) - LBound(TwoDarray) + 1, _
UBound(TwoDarray, 2) - LBound(TwoDarray, 2) + 1).Value = TwoDarray

Alan Beban
 
Top