Tim Hanson
Member
Hello,
@Chihiro wrote this code here: http://forum.chandoo.org/threads/matrix-to-list-database.35258/#post-210731
I have tried to alter it to do a straight un-pivot of a matrix with out any conditions but have failed at it
I think I need to remove this
I am hoping someone can help me
I have uploaded a workbook to show what I mean
Thanks for any help on this
@Chihiro wrote this code here: http://forum.chandoo.org/threads/matrix-to-list-database.35258/#post-210731
I have tried to alter it to do a straight un-pivot of a matrix with out any conditions but have failed at it
I think I need to remove this
Code:
For j = 2 To UBound(srcArr, 2)
If srcArr(i, 7) = srcArr(i, j) Then
.Item(kStr & "^" & srcArr(1, j)) = 1
End If
Next
I am hoping someone can help me
I have uploaded a workbook to show what I mean
Thanks for any help on this
Code:
Sub Demo()
Dim srcArr, resArr, Key, x
Dim i As Long, j As Long
Dim kStr As String
Dim sTime As Single, eTime As Double
sTime = Timer
With Sheets("Z")
srcArr = .Range(.Cells(1, "A"), .Cells(.UsedRange.Rows.Count, .UsedRange.Columns.Count)).Value
End With
With CreateObject("Scripting.Dictionary")
For i = 2 To UBound(srcArr)
For j = 1 To 1
kStr = IIf(Len(kStr) = 0, srcArr(i, j), kStr & "^" & srcArr(i, j))
Next
For j = 2 To UBound(srcArr, 2)
If srcArr(i, 7) = srcArr(i, j) Then
.Item(kStr & "^" & srcArr(1, j)) = 1
End If
Next
kStr = ""
Next
ReDim resArr(1 To .Count, 1 To 3)
i = 1
For Each Key In .Keys
x = Split(Key, "^")
For j = 0 To UBound(x)
resArr(i, j + 1) = x(j)
Next
i = i + 1
Next
End With
Sheets("Z").Range("A1:C1").Value = Sheets("DepivotedZ").Range("A1:C1").Value
Sheets("Z").Range("D1") = "Date"
Sheets("Z").Range("A2").Resize(UBound(resArr), 3) = resArr
eTime = Timer
Debug.Print eTime - sTime
End Sub