title: Is there a constraint on the depth level of grouping in Excel?
body: <p>I am trying to write a macro in Excel which will allow me to automatically do groupings based on the number located in the first column. Here is the code.</p>
  
  <pre><code>Sub Makro1()
  Dim maxRow As Integer
  Dim row As Integer
  Dim groupRow As Integer
  Dim depth As Integer
  Dim currentDepth As Integer
  
  maxRow = Range("A65536").End(xlUp).row
  
  For row = 1 To maxRow
      depth = Cells(row, 1).Value
      groupRow = row + 1
      currentDepth = Cells(groupRow, 1).Value
      If depth &gt;= currentDepth Then
         GoTo EndForLoop
      End If
      Do While currentDepth &gt; depth And groupRow &lt;= maxRow
          groupRow = groupRow + 1
          currentDepth = Cells(groupRow, 1).Value
      Loop
      Rows(row + 1 &amp; ":" &amp; groupRow - 1).Select
      Selection.Rows.Group
  EndForLoop:
      Next row
  End Sub
  </code></pre>
  
  <p>The first column in the Excel file looks like this:</p>
  
  <pre><code>1
  2
  2
  3
  3
  4
  4
  4
  4
  5
  5
  5
  6
  6
  6
  6
  5
  6
  6
  6
  7
  8
  8
  9
  10
  9
  10
  10
  8
  7
  7
  8
  6
  5
  4
  3
  2
  1
  2
  </code></pre>
  
  <p>When the macro reaches the depth 8 speaking of the groupings, I get error number 1004. It looks like the Excel does not allow me to create a depth greater than 8. Is there a workaround for this? I am using MS Excel 2003.</p>