Sub BuildHierarchyProduct()
Dim RowId As Long
Dim ColId As Long
Dim ColLevel As Long
Dim ColIsBase As Long
Dim ColOffset As Long
Dim ColOffsetName As Long
Dim ParentCode(64) As String
ColOffsetName = 58
' Column A contains the code level in hierarchy
ColLevel = 1
' Column B identifies if the code is base / leaf in hierarchy
ColIsBase = 2
' Column D is the first containing codes
ColOffset = 3
' Specify starting and ending rows
' AG 2019.05.27 -> For RowId = 2138 To 2938
' CE 2019.05.27 -> For RowId = 600 To 719
' AG_GPL 2019.05.27 -> For RowId = 3899 To 4488
' CE_GPL 2019.05.27 -> For RowId = 4493 To 4618
For RowId = 600 To 719
ColId = ColOffset + Cells(RowId, ColLevel).Value
' Cells(RowId, ColId).Select
ParentCode(ColId) = Cells(RowId, ColId).Value
Cells(RowId, 100).Value = RowId
Cells(RowId, 101).Value = ParentCode(ColId - 1)
Cells(RowId, 102).Value = Cells(RowId, ColId)
Cells(RowId, 103).Value = Cells(RowId, ColOffsetName)
' Cells(RowId, nnn).Value = Cells(RowId, ColIsBase)
'If Not IsEmpty(Cells(RowId, ColId).Value) Then
' Cells(RowId, ColId).Font.Color = vbGreen
'End If
Next RowId
End Sub