title: Grouping Rows in VBA
body: <p>I have the code below that doesn't seem to be working. Essentially, <code>rngList</code> refers to a defined name range in Excel that is about 500 rows long and every <code>n</code> number of rows there is text (there are approximately 32 rows out of the 500 that have text). I am trying to go to the non-blank cells (by mimicking the <code>ctrl + down</code> command in Excel). </p>
  
  <p>I am checking to see if they are blank, and if they are I want to group that cell. If it is not blank, I want to check the cell to the left and if it is 0, I also want to group it. The code I have now is essentially trying to do this but I am receiving the error below:</p>
  
  <p><code>Group Method of Range Class Failed</code></p>
  
  <p>It then goes on to highlight the following line:</p>
  
  <p><code>Selection.Rows.Group</code></p>
  
  <p>EDIT: Let's say instead of grouping rows that are blank, I want to group rows that have 1 in them. That way the crtl + down will actually go to that cell rather than the last row.</p>
  
  <p>Thank you very much for the help!</p>
  
  <p>The code  is below:</p>
  
  <pre><code>rngList.Cells(1).Select
      i = 0
  
      Do While i &lt; 32
          i = i + 1
          If Selection.Value = "" Then
              Selection.Rows.Group
          Else
              Selection.End(xlToLeft).Select
                  If Selection.Value &lt;&gt; 0 Then
                      Selection.Rows.ClearOutline
                  End If
          End If
          Selection.End(xlToRight).Select
          Selection.End(xlDown).Select
  
      Loop
  </code></pre>