Dim VariableCount As Integer
Dim MaxStates As Integer
Dim CurrentRow As Integer
Dim PrecedingCells()
Sub Test()
CurrentRow = 0
CurrentArrayColumn = 1
Dim SubArray()
VariableCount = 5
MaxStates = 5
Dim VariableStateArray()
ReDim SubArray(VariableCount - 2, MaxStates - 1)
ReDim PrecedingCells(VariableCount - 2)
ReDim VariableStateArray(VariableCount - 1, MaxStates - 1)
VariableStateArray(0, 0) = "V1S1"
VariableStateArray(0, 1) = "V1S2"
VariableStateArray(0, 2) = "V1S3"
VariableStateArray(0, 3) = "V1S4"
VariableStateArray(1, 0) = "V2S1"
VariableStateArray(1, 1) = "V2S2"
VariableStateArray(1, 2) = "V2S3"
VariableStateArray(2, 0) = "V3S1"
VariableStateArray(2, 1) = "V3S2"
VariableStateArray(2, 2) = "V3S3"
VariableStateArray(2, 3) = "V3S4"
VariableStateArray(3, 0) = "V4S1"
VariableStateArray(3, 1) = "V4S2"
VariableStateArray(3, 2) = "V4S3"
VariableStateArray(3, 3) = "V4S4"
VariableStateArray(4, 0) = "V5S1"
VariableStateArray(4, 1) = "V5S2"
VariableStateArray(4, 2) = "V5S3"
VariableStateArray(4, 3) = "V5S4"
VariableStateArray(4, 4) = "V5S5"
Call ProcessArray(VariableStateArray)
End Sub
Sub ProcessArray(WorkingVariableStateArray As Variant)
StateCount = 0
For M = 0 To UBound(WorkingVariableStateArray, 2)
If WorkingVariableStateArray(N, M) <> "" Then StateCount = StateCount + 1
Next M
Dim SubArray()
Call ReduceArray(WorkingVariableStateArray, SubArray, N)
For M = 0 To StateCount - 1
PrecedingCells(VariableCount - UBound(WorkingVariableStateArray, 1) - 1) = WorkingVariableStateArray(N, M)
Call AddCells(PrecedingCells, SubArray)
Next M
End Sub
Sub AddCells(ByVal PrecedingCells As Variant, ByVal SmallerArray As Variant)
If UBound(SmallerArray, 1) <> 0 Then
PrecedingCells(UBound(PrecedingCells) - UBound(SmallerArray, 1) + 1) = SmallerArray(0, Z)
Call ProcessArray(SmallerArray)
Else
For B = 0 To UBound(SmallerArray, 2)
CurrentRow = CurrentRow + 1
For A = 0 To UBound(PrecedingCells)
Cells(CurrentRow, A + 1) = PrecedingCells(A)
Next A
Cells(CurrentRow, UBound(PrecedingCells) + 2) = SmallerArray(0, B)
Next B
End If
End Sub
Sub ReduceArray(ByVal OriginalArray As Variant, ByRef NewArray As Variant, ByVal ElementToIgnore As Integer)
ReDim NewArray(UBound(OriginalArray, 1) - 1, UBound(OriginalArray, 2))
CurrentNewArrayRow = 0
For X = 0 To UBound(OriginalArray, 1)
If X <> ElementToIgnore Then
CurrentNewArrayRow = CurrentNewArrayRow + 1
For Y = 0 To UBound(OriginalArray, 2)
NewArray(CurrentNewArrayRow - 1, Y) = OriginalArray(X, Y)
Next Y
End If
Next X
End Sub
Bookmarks