Results 1 to 5 of 5

parent-child relationship in a tree diagram using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    03-20-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    4

    parent-child relationship in a tree diagram using VBA

    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
    Attached Files Attached Files
    Last edited by ruiru; 03-20-2020 at 11:55 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Parent Child relationship issue: Get parent ID for child
    By masterl1983 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-28-2018, 07:35 AM
  2. [SOLVED] Sorting with Parent and Child
    By dominict in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-04-2013, 06:56 AM
  3. [SOLVED] Parent child relationships(working out parent item) for each item
    By grphillips in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-21-2013, 05:58 AM
  4. Parent Child Relationship
    By Automation Guru in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-02-2013, 04:48 AM
  5. Vba code for Parent child
    By ken4ward in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2012, 06:04 AM
  6. Replies: 4
    Last Post: 08-30-2009, 03:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1