+ Reply to Thread
Results 1 to 11 of 11

VBA for Organizational Chart (Filtered)

Hybrid View

  1. #1
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    VBA for Organizational Chart (Filtered)

    Hi!

    Can you help me with this code?

    Sub MakeHierarchy()
    '
    '
    Dim shpHolder As Shape
    Dim objMain As SmartArt
    Dim objNode As SmartArtNode
    Dim rngData As Range
    Dim lngRow As Long

    Set rngData = Range("A2:E1000")

    Set shpHolder = ActiveSheet.Shapes.AddSmartArt(Application.SmartArtLayouts( _
    "urn:microsoft.com/office/officeart/2005/8/layout/orgChart1"))

    Set objMain = shpHolder.SmartArt

    'clear default nodes
    Do While objMain.AllNodes.Count > 1
    objMain.AllNodes(objMain.AllNodes.Count).Delete
    Loop

    lngRow = 1
    Set objNode = objMain.AllNodes(1)
    objNode.TextFrame2.TextRange.Text = rngData.Cells(lngRow, 3)


    For lngRow = 2 To rngData.Rows.Count
    lngParentIndex = Application.WorksheetFunction.Match(rngData.Cells(lngRow, 2), rngData.Columns(1), 0)
    Set objNode = objMain.AllNodes(lngParentIndex).AddNode(msoSmartArtNodeBelow, msoSmartArtNodeTypeDefault)
    objNode.TextFrame2.TextRange.Text = rngData.Cells(lngRow, 3)
    Next

    End Sub
    Sub Macro2()
    '
    ' Macro2 Macro
    '

    '
    Call ActiveSheet.Shapes.AddSmartArt(Application.SmartArtLayouts( _
    "urn:microsoft.com/office/officeart/2005/8/layout/orgChart1")).Select
    End Sub



    for the range... i can't select the filtered section of the chart. do you know the code for me to just select the visible data?
    I have just got that code here. hope you can help me with this one.
    Also do you know how to make it a button?

    Thank you so much in advance...

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA for Organizational Chart (Filtered)

    Hi the code for visible cells only is...

    Selection.SpecialCells(xlCellTypeVisible).Select
    To make a macro into a button, just create a shape and right click on the shape and select "Assign Macro's"
    Last edited by spitfireblue; 01-19-2016 at 01:35 AM.

  3. #3
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA for Organizational Chart (Filtered)

    Hi,

    Thank you for the info.

    How can I use that for the range?

    Set rngData = Range("A2:E1000")

    If only visible data would I use, how can I set my rngData?


    Thank you so much in advance

  4. #4
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA for Organizational Chart (Filtered)

    Set rngData = Range("A2:E1000").SpecialCells(xlCellTypeVisible)
    Last edited by spitfireblue; 01-19-2016 at 01:35 AM.

  5. #5
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA for Organizational Chart (Filtered)

    Thank you...

    I've tried it with the data I've had but it seems like the data was not all captured.

    rank link to rank name region
    a a 1
    b a b 2
    c b c 3
    d b d 2
    e d e 2


    this is the sample data...

    if i filtered 1 and 2,
    just ''a"' and "b" would appear.

    How will I format the range so that a,b,d and e would be shown in the graph?

    Thank you.

  6. #6
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA for Organizational Chart (Filtered)

    Can you send through a sample sheet with the graph?

  7. #7
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA for Organizational Chart (Filtered)

    Here's the sample data.

    sample data.xlsx

    Also can it be possible to program the background color of the charts depending on their positions/regions?

    Thank you very much for the help.


  8. #8
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA for Organizational Chart (Filtered)

    Hmm, not sure!?!?
    I haven't played around much with smart art before. I know that people have been having problems linking smart art to cells.
    The visible cells code is working as per the attached... maybe you can copy the filtered data into a new sheet first?
    Visible Cells Example.xlsm

  9. #9
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA for Organizational Chart (Filtered)

    Thanks for this spitfireblue. but how can i make it into a hierarchy? do you know a code?

    Sorry for a lot of queries.

    I need a lot of macros to be implemented. subtotal with different criterias, automatic chart and so on.

    Thanks for your response appreciate it much.


  10. #10
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA for Organizational Chart (Filtered)


  11. #11
    Registered User
    Join Date
    12-28-2015
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA for Organizational Chart (Filtered)

    Hi,

    I've tried looking at it, but it seems that it wasn't the info i've been seeking for. but anyway thank you for this,

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Creating a company organizational chart
    By ecadams in forum Excel General
    Replies: 1
    Last Post: 07-07-2015, 05:07 PM
  2. Cell Link to (or from) Organizational Chart
    By Flashes24 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-27-2013, 02:07 PM
  3. Organizational chart in Excel
    By vjharry in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-08-2013, 10:09 AM
  4. [SOLVED] organizational chart that will not print
    By dhill1998 in forum Excel General
    Replies: 0
    Last Post: 04-27-2006, 12:10 PM
  5. How can I reformat an Organizational Chart?
    By nancywancy in forum Excel General
    Replies: 0
    Last Post: 03-07-2006, 02:35 PM
  6. [SOLVED] Organizational Chart
    By Brenda Rueter in forum Excel General
    Replies: 1
    Last Post: 05-19-2005, 02:08 PM
  7. [SOLVED] is there a template to put together an organizational chart in Ex.
    By rachel1027 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-14-2005, 03:06 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