roberto
11/30/2017 - 6:33 PM

Account hierarchy from HFM metadata

Crea la gerarchia con codice parent e child partendo da gerarchia HFM file di Luca

Sub BuildHierarchyAccount()
    ' Usage: at column 100 and following there are the values to use
    ' ParentCode, Code, IsBaseAccount, Name, ParentType, Type, InScope
    ' when ParentType and Type are different then the sign must be minus (-)
    ' when InScope is empty that account is not meaningful for that branch (AG, CE, CV, etc)
    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 ColOffsetInScope As Long
    Dim ColOffsetType As Long
    Dim ParentCode(64) As String
    Dim ParentType(64) As String
    ColOffsetName = 81
    ' 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 = 4
    ' Column AB (28) means the account is in scope for Layer2-AG if contains X
    ' Column AF (32) means the account is in scope for Layer2-CE if contains X
    ' !!! NOTE !!! as of 24.05.2019 AG and CE are identical
    ColOffsetInScope = 32
    ' Column AU contains the type of account: expense or revenue
    ColOffsetType = 42
    ' ColId = ActiveCell.Column
    ' For RowId = ActiveCell.Row To Rows.Count
    ' For RowId = 1490 To 2238 gerarchia con STA1000
    ' For RowId = 8 To 762 gerarchia con UIA025
    For RowId = 1490 To 2238
        ColId = ColOffset + Cells(RowId, ColLevel).Value
        ' Cells(RowId, ColId).Select
        ParentCode(ColId) = Cells(RowId, ColId).Value
        ParentType(ColId) = Cells(RowId, ColOffsetType).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, 104).Value = ParentType(ColId - 1)
        Cells(RowId, 105).Value = Cells(RowId, ColOffsetType)
        Cells(RowId, 106).Value = Cells(RowId, ColOffsetInScope)
        ' Cells(RowId, nnn).Value = Cells(RowId, ColIsBase) in new file version with financial this info is no more good
        'If Not IsEmpty(Cells(RowId, ColId).Value) Then
        '    Cells(RowId, ColId).Font.Color = vbGreen
        'End If
    Next RowId
End Sub