Reconstructing a table with Arrays

  • Thread starter Thread starter Bythsx-Addagio
  • Start date Start date
B

Bythsx-Addagio

Hello,
I am hoping to work out a method to transform a data table into a running
list.
The table has identifiers in column A, and product weights in a dynamic
number of columns to the right. i.e. Cols B-M. I would like to manipulate
the table into a running list of three columns

Col A = Value of ID @ row(i)
Col B = Product name [value of Cols B-M row(1)]
Col C = Value of weight @ row(i)

Col A | Col B | Col C
A2 B1 B2
A3 B1 B3
A4 B1 B4
A2 C1 C2
A3 C1 C3
A4 C1 C4
A2 D1 A2 ... etc.

I was thinking a 2D array might be the correct approach. Would there be a
better solution? And if the Array is the way to go, where would be the best
place to start?

Thanks in advance,
 
Hi Bythsx-Addagio,

In Excel 2007 I have crated this macro


Sub Adagio()
Dim lastRow As Long
Dim lastCol As Long
Dim loopRow As Long
Dim loopCol As Long
Dim outputRow As Long

lastRow = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
lastCol = Cells(1, ActiveSheet.Columns.Count).End(xlToLeft).Column

outputRow = 1
For loopRow = 2 To lastRow
For loopCol = 2 To lastCol
If Not IsEmpty(ActiveSheet.Cells(loopRow, loopCol)) Then
outputRow = outputRow + 1
Sheets("Sheet2").Cells(outputRow, 1) =
ActiveSheet.Cells(loopRow, 1)
Sheets("Sheet2").Cells(outputRow, 2) = ActiveSheet.Cells(1,
loopCol)
Sheets("Sheet2").Cells(outputRow, 3) =
ActiveSheet.Cells(loopRow, loopCol)
End If
Next
Next

End Sub

HTH,

Wouter.
 
Back
Top