<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Modern Legal Support &#187; Excel</title>
	<atom:link href="https://modernlegalsupport.com/category/excel/feed/" rel="self" type="application/rss+xml" />
	<link>https://modernlegalsupport.com</link>
	<description>The modern approach to legal document support.</description>
	<lastBuildDate>Fri, 07 Dec 2018 00:25:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Excel – Use Grouping to Show Tree Structure</title>
		<link>https://modernlegalsupport.com/2017/02/02/excel-use-grouping-to-show-tree-structure/</link>
		<comments>https://modernlegalsupport.com/2017/02/02/excel-use-grouping-to-show-tree-structure/#comments</comments>
		<pubDate>Thu, 02 Feb 2017 12:16:40 +0000</pubDate>
		<dc:creator><![CDATA[Kenneth Hester]]></dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://modernlegalsupport.com/?p=436</guid>
		<description><![CDATA[Note: This solution was tested in Excel 2013 and 2010. Great tool for data room indexes The other day at the office, I had an interesting request. An attorney had an Excel index from a data room, and wanted to use Excel&#8217;s grouping feature to represent the file/folder structure. The data room, as is typical, &#8230; <a href="https://modernlegalsupport.com/2017/02/02/excel-use-grouping-to-show-tree-structure/" class="more-link">Continue reading <span class="screen-reader-text">Excel – Use Grouping to Show Tree Structure</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<aside>Note: This solution was tested in Excel 2013 and 2010.</aside>
<h2>Great tool for data room indexes</h2>
<p>The other day at the office, I had an interesting request. An attorney had an Excel index from a data room, and wanted to use Excel&#8217;s grouping feature to represent the file/folder structure.</p>
<p>The data room, as is typical, had an index column that used a string concatenated from integers to represent file and folder location. For instance, &#8220;1,&#8221; &#8220;2,&#8221; &#8220;3&#8221; etc. are the top-level folders. &#8220;1.1&#8221; may be a subfolder or a file under folder 1, etc.:</p>
<p><img src="http://modernlegalsupport.com/images/excel-dataroom-index.png" width="411" height="435" title="Excel dataroom index" /></p>
<p>What the attorney wanted was to have the grouping &#8220;plus signs&#8221; at each folder level, grouping the files and subfolders below that folder.</p>
<p>I came up with the solution using VBA code and one helpful setting in Excel. First, the setting. Excel by default places the summary rows (i.e., the plus signs) <em>below</em> the detail, or group. In this application, we want the plus signs <em>above</em> the group. To allow this, click the dialog launcher under <strong>Data</strong> &gt; <strong>Outline</strong> and uncheck &#8220;Summary rows below detail.&#8221; This is a worksheet-level setting, so it will stick with your sheet.</p>
<p><img src="http://modernlegalsupport.com/images/excel-grouping-settings.png" width="359" height="173" Title="Excel grouping settings" /></p>
<p>Another issue to be aware of: Your index column should be formatted as text, so that, for instance, &#8220;1.20&#8221; does not come into Excel as &#8220;1.2&#8221; etc. &#8220;1.20&#8221; in a data room index means the 20th item under 1, but if your cell is formatted as General, Excel will treat it as a number and drop the insignificant zero.</p>
<p>Also be aware that Excel gives you a maximum of 8 grouping levels, so this solution won&#8217;t cover grouping deeper levels than that.</p>
<p>Now for the code. It&#8217;s fairly compact and quick to run. It determines the level of the current record by the number of tokens in the index string, then applies logic based on the current record&#8217;s relation to what has come before it in the loop, grouping at each level in the tree.</p>
<p class="disclaimer">Modern Legal Support provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. <strong>Always back up your documents before running any code.</strong></p>
<div>
<pre class="code">
Option Explicit
 
' Code by Kenneth A. Hester
' www.modernlegalsupport.com

Sub GroupFoldersByLevel()
    Dim i As Long
    Dim r As Range
    Dim rStart As Range
    Dim rEnd As Range
    Dim foundStart As Boolean
    Dim rngGroup As Range
    Dim level As Long
    Dim maxLevel As Long
    Dim levelAtRow As Long
    Dim indexColumn As Long
    Dim fileFolderColumn As Long
    Dim startRow As Long
    Dim atEndRow As Boolean
   
    ' ----------------------
    ' set these values based on your worksheet:
    maxLevel = 7
    indexColumn = 1
    fileFolderColumn = 3
    startRow = 3
    ' ----------------------
   
    For level = 1 To maxLevel
        DoEvents
        Debug.Print "Processing level " &#038; CStr(level) &#038; "..."
        
        foundStart = False
        For i = startRow To ActiveSheet.UsedRange.Rows.Count + 1
            Set r = ActiveSheet.Rows(i)
            atEndRow = (i = ActiveSheet.UsedRange.Rows.Count + 1) ' close off last groups at end row
            
            ' determine level of current row based on number of tokens in index:
            levelAtRow = UBound(Split(CStr(r.Cells(indexColumn).Value), ".")) + 1
            
            If levelAtRow <= level Or atEndRow Then
            ' found a file or folder at or above the level
                If Not foundStart Then
                ' then we found the start of a group
                    If levelAtRow = level And Trim$(LCase$(r.Cells(fileFolderColumn).Value)) = "folder" Then
                        ' it's a folder at the level
                        Set rStart = r.Offset(1) ' start grouping the files below the folder
                        foundStart = True
                    End If
                Else ' already found start of the group, so now we found the end
                    Set rEnd = r.Offset(-1)
                    If Not rStart.Row > rEnd.Row Then ' this takes care of empty folders
                        Set rngGroup = Range(rStart, rEnd) ' close the group
                        rngGroup.Rows.Group
                    End If
                    If levelAtRow = level And Trim$(LCase$(r.Cells(fileFolderColumn).Value)) = "folder" Then
                        ' if the end is the start of another folder at the level
                        ' reset the start row
                        Set rStart = r.Offset(1)
                        foundStart = True
                    Else
                        foundStart = False
                    End If
                    'Exit Sub
                End If
            End If
        Next i
    Next level
    
    Debug.Print "done."
End Sub
</pre>
</div>
<p>After running the code:</p>
<p><img src="http://modernlegalsupport.com/images/excel-dataroom-index-grouped.png" width="549" height="457" title="Excel dataroom index after grouping" /></p>
<p>You can download my Excel test file with the code <a href="http://modernlegalsupport.com/downloads/hester-tree-grouping.xlsm">here</a>.</p>
<p>Have fun. Let me know if it works for you.</p>
<p class="credentials">Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.</p>
]]></content:encoded>
			<wfw:commentRss>https://modernlegalsupport.com/2017/02/02/excel-use-grouping-to-show-tree-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
