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):
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
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