Hi Folks,
I am trying to take a wide format array and using vba convert it to a tall skinny format.
Currently my xl2bb is blocked so I pasted an example table at the bottom of this. Example wide format on left, desired format on right)
My starting code is here. I've tried a few different variations, sometimes closer to what I want sometimes farther, but not quite where I want to be.
I am trying to take a wide format array and using vba convert it to a tall skinny format.
Currently my xl2bb is blocked so I pasted an example table at the bottom of this. Example wide format on left, desired format on right)
My starting code is here. I've tried a few different variations, sometimes closer to what I want sometimes farther, but not quite where I want to be.
VBA Code:
Sub WideToSkinny()
Dim lastRow, lastCol, i, j, totRows As Long
Dim wsIn, wsOut As Worksheet
Dim inArray, outArray As Variant
Set wsIn = Worksheets("Sheet1")
Set wsOut = Worksheets("Sheet2")
lastRow = wsIn.Cells(Rows.Count, 1).End(xlUp).Row
lastCol = wsIn.Cells(1, Columns.Count).End(xlToLeft).Column
wsOut.Cells.Clear
inArray = wsIn.Range("A1").CurrentRegion.Value
totRows = (lastRow * (lastCol - 1)) - 1
ReDim outArray(1 To 1, 1 To totRows)
For j = 1 To lastCol
For i = 1 To lastRow
'###This copies the date column, but I need it to repeat
'###depending on number of data columns
outArray(1, i) = inArray(i, 1)
'###Missing code to get the additonal columns and put item/values in right place
Next i
Next j
MsgBox "Wait"
End Sub
Date | A | B | Item | Date | Value | ||||||
11/1/2000 | 0 | 1327 | A | 11/1/2000 | 0 | ||||||
12/1/2000 | 0 | 6427 | A | 12/1/2000 | 0 | ||||||
1/1/2001 | 0 | 6726 | A | 1/1/2001 | 0 | Desired Result | |||||
2/1/2001 | 6786 | 6098 | A | 2/1/2001 | 6786 | ||||||
3/1/2001 | 8360 | 5986 | A | 3/1/2001 | 8360 | ||||||
4/1/2001 | 9889 | 4327 | A | 4/1/2001 | 9889 | ||||||
5/1/2001 | 9255 | 5485 | A | 5/1/2001 | 9255 | ||||||
6/1/2001 | 8620 | 5721 | A | 6/1/2001 | 8620 | ||||||
7/1/2001 | 7226 | 6161 | A | 7/1/2001 | 7226 | ||||||
B | 11/1/2000 | 1327 | |||||||||
B | 12/1/2000 | 6427 | |||||||||
B | 1/1/2001 | 6726 | |||||||||
B | 2/1/2001 | 6098 | |||||||||
B | 3/1/2001 | 5986 | |||||||||
B | 4/1/2001 | 4327 | |||||||||
B | 5/1/2001 | 5485 | |||||||||
B | 6/1/2001 | 5721 | |||||||||
B | 7/1/2001 | 6161 |