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:

[TABLE="class: grid, width: 800"]
<tbody>[TR]
[TD]Column1
[/TD]
[TD]Column2
[/TD]
[TD]Column3
[/TD]
[TD]Column4
[/TD]
[TD]Column5
[/TD]
[/TR]
[TR]
[TD]matVendor(1,1)
[/TD]
[TD]matVendor(2,1)
[/TD]
[TD]matVendor(3,1)
[/TD]
[TD]matVendor(4,1)
[/TD]
[TD]matVendor(5,1)
[/TD]
[/TR]
[TR]
[TD]matVendor(1,2)
[/TD]
[TD]matVendor(2,2)
[/TD]
[TD]matVendor(3,2)
[/TD]
[TD]matVendor(4,2)
[/TD]
[TD]matVendor(5,2)
[/TD]
[/TR]
[TR]
[TD]matVendor(1,3)
[/TD]
[TD]matVendor(2,3)
[/TD]
[TD]matVendor(3,3)
[/TD]
[TD]matVendor(4,3)
[/TD]
[TD]matVendor(5,3)
[/TD]
[/TR]
[TR]
[TD]matVendor(1,4)
[/TD]
[TD]matVendor(2,4)
[/TD]
[TD]matVendor(3,4)
[/TD]
[TD]matVendor(4,4)
[/TD]
[TD]matVendor(5,4)
[/TD]
[/TR]
</tbody>[/TABLE]

Any ideas?

Cheers,

James
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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