I have a table with the first column containing some numbers and I want to loop through and group the rows of my table based on the values in this first column so that they can be collapsible. So similar to what shift+alt+right does. As an example I would want to convert a table with rows like this

1 

1 

2

3 

3

3

Into a table like this with each grouping being expandable and on the same level.

1

2

3

I have been trying to change the macro I found from <https://superuser.com/questions/867796/excel-macro-to-group-rows-based-on-a-cell-value>. My current macro is... 

```
Dim LastRow As Integer
LastRow = ActiveSheet.UsedRange.Rows.Count
Dim StartRow As Integer
StartRow = 8

groupBegin = StartRow 'For the first group
For i = StartRow To LastRow

    If Cells(i, 1).Value <> Cells(i + 1, 1).Value Then
        groupEnd = i - 1
        Rows(groupBegin & ":" & groupEnd).Select
        Selection.Rows.Group
        groupBegin = i + 1 'adding one to keep the group's first row
    End If

Next i

Rows(groupBegin & ":" & LastRow).Select
Selection.Rows.Group

ActiveSheet.Outline.ShowLevels RowLevels:=1 'Minimize all the groups

```

This however groups all the rows together. Any guidance on how to achieve this would be appreciated.