transform array of varying lengths

MetLife

Active Member
Joined
Jul 2, 2012
Messages
283
Hi,

I have been fiddling with this logic, but I can't seem to make it work.

Basically I just want to transpose arrays with varying lengths using the Ubound property.

Here is the original code:

Set rng = Range("VBAOutput")
rng.offset(0, 229).Value = Application.Transpose(array)

THANKS
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
MetLife,

The following might get you started...

Code:
Sub testArr()
Dim rng As Range, r As Long, c As Long
Dim arr As Variant
Set rng = Range("VBAOutput")
arr = rng.Value

r = UBound(arr)
c = UBound(arr, 2)
Range(Cells(rng.Row, rng.Column), Cells(c, r)).Offset(0, 229).Value = Application.Transpose(arr)
End Sub

Cheers,

tonyyy
 
Upvote 0
If your array is 2-dimentional, code like this will work.
Code:
Set rng = Range("VBAOutput")

With rng
    .Resize(UBound(someArray,2), UBound(someArray,1)).Value = Application.Transpose(someArray)
End With

If someArray is a one dimensional array then
Code:
Rng.Resize(Ubound(someArray),1).Value = Application.Transpose(someArray)

BTW, Array is a reserved word in VBA and can't be used as a variable name.
 
Upvote 0
Another way:

Code:
Sub testArr()
  With Range("VBAOutput")
    .Offset(229).Resize(.Columns.Count, .Rows.Count).Value2 = Application.Transpose(.Value2)
  End With
End Sub
 
Upvote 0
If someArray is a one dimensional array then
Code:
Rng.Resize(Ubound(someArray),1).Value = Application.Transpose(someArray)
It might depend on how the one-dimensional array came into being. If the Split function was used, or if the Array function was used with the Option Base defaulted to or set to 0, then you would have to use UBound(someArray)+1 inside the Resize property call.
 
Upvote 0
Good catch. If I remember correctly the full expression should be UBound(someArray) + (1 - LBound(someArray))
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top