Grouping of Hierarchy

NickvdB

Board Regular
Joined
Apr 30, 2014
Messages
71
Hi all,

Can someone help to have the following table auto-grouped? VBA would be easiest I think.
The goal is to have the hierarchy in a good overview people can get to the desired level and fill something in on the columns I will paste next to the table. And therefore Pivot will not work because of change rows when collapsing and expanding.

Level 1Level 2Level 3
1
11
111
112
113
12
121
122
2
21
22
221
222
223

<tbody>
</tbody>

Thanks
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Can someone help to have the following table auto-grouped?
Care to show us what the expected results would look like for that sample data & explain in relation to those results?
 
Upvote 0
Care to show us what the expected results would look like for that sample data & explain in relation to those results?

Level 1Level 2Level 3
+1
1+1
111
112
113
1+2
121
122
+2
2+1
2+2
221
222
223

<tbody>
</tbody>

So basically being able to collapse and expand with the plusses on these levels above. Just a normal grouping.
 
Upvote 0
I'm not quite sure whether those '+' cells actually conatin that symbol. For the code below, I have assumed that they do not and the data looks like post 1.
To collapse/expand rows, you would double-click that top cell in a group (effectively a '+' cell) and the code should toggle hiding/showing that group of cells, always leaving the top row of the group visible.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Dim s As String
  Dim r As Long, i As Long
  
  s = Target.Text
  r = Target.Row
  If Target.Column < 4 And r > 1 And Len(s) > 0 Then
    If Target.Offset(-1).Value <> s Then
      Cancel = True
      Do
        i = i + 1
      Loop Until Target.Offset(i).Text <> s
      If i > 1 Then
        Rows(r + 1).Resize(i - 1).Hidden = Not Rows(r + 1).Hidden
      End If
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top