i have macro for parent child hierarchy macro but i want to run the same for more than 20000 rows can it be speed up
VBA 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
Sub CreateReport()
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
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 AddChildren(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
End Sub
Sub AddChildren(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
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 AddChildren(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