I am building a organisational structure for a company. However, my current VBA script does not have a parent-child relationship eg(Trainer under Team Leader). How can i create the relationship in macro and display it in the organisational structure? In the picture below, Jodan and Sky are supposed to be under Jane. I have not created a parent column yet but i have no idea how to go about writing the code to link the child(Jodan and Sky) to the parent(Jane) so that they appear below Jane instead of below Kite. Thank you for your help!
This is my VBA code:
org()
org Macro
'Macro to generate organization chart
'
' Keyboard Shortcut: Ctrl+j
'
Dim ogSALayout As SmartArtLayout
Dim QNode As SmartArtNode
Dim QNodes As SmartArtNodes
Dim t As Integer
Set ogSALayout = Application.SmartArtLayouts(92) 'reference to organization chart
Set ogShp = ActiveWorkbook.ActiveSheet.Shapes.AddSmartArt(ogSALayout)
Set QNodes = ogShp.SmartArt.AllNodes
t = QNodes.Count
While QNodes.Count < t
QNodes(QNodes.Count).Delete
Wend
While QNodes.Count < Range("A1").End(xlDown).Row
QNodes.Add.Promote
Wend
For i = 1 To Range("A1").End(xlDown).Row
'Promote and demote nodes to put them at the proper level.
While QNodes(Range("A" & i)).Level < Range("C" & i).Value
QNodes(Range("A" & i)).Demote
Wend
'Copy the cell text to the node.
QNodes(Range("A" & i)).TextFrame2.TextRange.Text = Range("B" & i)
Next i
End Sub
structure.PNG
Bookmarks