Code:
Sub WonDeeArrayOfArrays() ' https://eileenslounge.com/viewtopic.php?p=266691#p266691
Dim arr1D(1 To 2) As Variant
Let arr1D(1) = Array("a", "b")
Let arr1D(2) = Array("c", "d")
Dim arrOut() As Variant
Let arrOut() = Application.Index(arr1D(), Evaluate("=ROW(1:2)"), Array(1, 2))
Let arrOut() = Application.Index(arr1D(), Evaluate("=ROW(1:2)"), Evaluate("=COLUMN(A:B)"))
End Sub
Code:
Option Explicit
Const SourceDivCol = 1
Const SourcePosCol = 2
Const SourceRepCol = 3
Const SourceLevCol = 4
Const SourceEmpCol = 5
Const SourceCodCol = 6
Const TargetDivCol = 15
Const TargetLevCol = 16
Const TargetPosCol = 17
Const TargetEmpCol = 18
Const TargetCodCol = 19
Dim SourceRow As Long
Dim TargetRow As Long
Dim Cnt As Long
Dim WunDeeArrayOfArrays() As Variant
Sub CreateReportHansAlan2() '
ReDim WunDeeArrayOfArrays(1 To Cells(1).CurrentRegion.Rows.Count - 2)
Dim Boss As Range
Dim Adr As String
Dim Pos As String
Application.ScreenUpdating = False
TargetRow = 2
Set Boss = Columns(SourceLevCol).Find(What:=1, LookAt:=xlWhole)
Adr = Boss.Address
Do
SourceRow = Boss.Row
TargetRow = TargetRow + 1
Let Cnt = Cnt + 1: Let WunDeeArrayOfArrays(Cnt) = Application.Index(Cells, SourceRow, Array(SourceDivCol, SourceLevCol, SourcePosCol, SourceEmpCol, SourceCodCol))
' Let Range("O" & TargetRow & ":S" & TargetRow & "").Value2 = Application.Index(Cells, SourceRow, Array(1, 4, 2, 5, 6))
' Let Range("O" & TargetRow & ":S" & TargetRow & "").Value2 = Application.Index(Cells, SourceRow, Array(SourceDivCol, SourceLevCol, SourcePosCol, SourceEmpCol, SourceCodCol))
' Cells(TargetRow, TargetDivCol).Value = Cells(SourceRow, SourceDivCol).Value
' Cells(TargetRow, TargetLevCol).Value = Cells(SourceRow, SourceLevCol).Value
' Cells(TargetRow, TargetPosCol).Value = Cells(SourceRow, SourcePosCol).Value
' Cells(TargetRow, TargetEmpCol).Value = Cells(SourceRow, SourceEmpCol).Value
' Cells(TargetRow, TargetCodCol).Value = Cells(SourceRow, SourceCodCol).Value
Pos = Cells(SourceRow, SourcePosCol).Value
Call AddKids(Pos)
Set Boss = Columns(SourceLevCol).Find(What:=1, After:=Boss, LookAt:=xlWhole)
If Boss Is Nothing Then Exit Do
Loop Until Boss.Address = Adr
Application.ScreenUpdating = True
Let Range("O3").Resize(Cells(1).CurrentRegion.Rows.Count - 2, 5).Value2 = Application.Index(WunDeeArrayOfArrays, Evaluate("=ROW(1:" & Cells(1).CurrentRegion.Rows.Count - 2 & ")"), Evaluate("=COLUMN(A:E)"))
End Sub
Sub AddKids(BossPos As String) '
Dim Child As Range
Dim Adr As String
Dim Pos As String
Set Child = Columns(SourceRepCol).Find(What:=BossPos, LookAt:=xlWhole)
If Child Is Nothing Then Exit Sub
Adr = Child.Address
Do
SourceRow = Child.Row
TargetRow = TargetRow + 1
Let Cnt = Cnt + 1: Let WunDeeArrayOfArrays(Cnt) = Application.Index(Cells, SourceRow, Array(SourceDivCol, SourceLevCol, SourcePosCol, SourceEmpCol, SourceCodCol))
' Let Range("O" & TargetRow & ":S" & TargetRow & "").Value2 = Application.Index(Cells, SourceRow, Array(SourceDivCol, SourceLevCol, SourcePosCol, SourceEmpCol, SourceCodCol))
' Cells(TargetRow, TargetDivCol).Value = Cells(SourceRow, SourceDivCol).Value
' Cells(TargetRow, TargetLevCol).Value = Cells(SourceRow, SourceLevCol).Value
' Cells(TargetRow, TargetPosCol).Value = Cells(SourceRow, SourcePosCol).Value
' Cells(TargetRow, TargetEmpCol).Value = Cells(SourceRow, SourceEmpCol).Value
' Cells(TargetRow, TargetCodCol).Value = Cells(SourceRow, SourceCodCol).Value
Pos = Cells(SourceRow, SourcePosCol).Value
Call AddKids(Pos)
Set Child = Columns(SourceRepCol).Find(What:=BossPos, After:=Child, LookAt:=xlWhole)
If Child Is Nothing Then Exit Do
Loop Until Child.Address = Adr
End Sub
Bookmarks