Sub BuildHierarchyMarket()
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 = 56
' Column A contains the account level in hierarchy
ColLevel = 1
' Column B identifies if the account is base / leaf in hierarchy
ColIsBase = 2
' Column D is the first containing account codes
ColOffset = 3
' ColId = ActiveCell.Column
' For RowId = ActiveCell.Row To Rows.Count
For RowId = 3 To 310
ColId = ColOffset + Cells(RowId, ColLevel).Value
' Cells(RowId, ColId).Select
ParentCode(ColId) = Cells(RowId, ColId).Value
Cells(RowId, 100).Value = ParentCode(ColId - 1)
Cells(RowId, 101).Value = Cells(RowId, ColId)
Cells(RowId, 102).Value = Cells(RowId, ColIsBase)
Cells(RowId, 103).Value = Cells(RowId, ColOffsetName)
'If Not IsEmpty(Cells(RowId, ColId).Value) Then
' Cells(RowId, ColId).Font.Color = vbGreen
'End If
Next RowId
End Sub