Output 2d Aray to Range verticaly

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Hey,

I have a 2d array (dynamic number of "rows" and 5 "columns").

My array is populated as follows (This has been simplified, the actual population is much more complex):

Code:
Sub foo()
    Dim lRow As Long, i As Long, x As Long
    Dim matVendor() As String
    lRow = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
    x = 0
    For i = 1 To lRow
        With Sheets(2).Cells(i, 1)
            If .Value = "x" Then
                x = x + 1
                ReDim Preserve matVendor(1 To 5, 1 To x)
                
                matVendor(1, x) = .Offset(-1, 0).Value
                matVendor(2, x) = .Offset(3, 0).Value
                matVendor(3, x) = .Offset(6, 2).Value
                matVendor(4, x) = .Offset(6, 3).Value
                matVendor(5, x) = .Offset(5).Value
            End If
        End With
    Next i
    Erase matVendor()
    i = Empty
    lRow = Empty
    x = Empty
End Sub

I want to output the contents of this array into a spreadsheet vertically (I used this, which output horizontaly - I couldn't figure out how to transpose it) so that it looks like this:

Column1
Column2
Column3
Column4
Column5
matVendor(1,1)
matVendor(2,1)
matVendor(3,1)
matVendor(4,1)
matVendor(5,1)
matVendor(1,2)
matVendor(2,2)
matVendor(3,2)
matVendor(4,2)
matVendor(5,2)
matVendor(1,3)
matVendor(2,3)
matVendor(3,3)
matVendor(4,3)
matVendor(5,3)
matVendor(1,4)
matVendor(2,4)
matVendor(3,4)
matVendor(4,4)
matVendor(5,4)

<tbody>
</tbody>

Any ideas?

Cheers,

James
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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