title: Group By With VBA
body: <p>I have a worksheet that has a header row, and I want to group the rows using VBA.  I have attempted this syntax</p>
  
  <pre><code>Sub GroupItTogether()
    Dim rLastCell As Range
    Set rLastCell = ActiveSheet.Cells.Find(What:="*", After:=.Cells(1, 1),  _   
      LookIn:=xlFormulas, LookAt:= _
      xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
    Range("A2" &amp; rLastCell).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1
  End Sub
  </code></pre>
  
  <p>However, this will produce an error of:</p>
  
  <blockquote>
    <p>Invalid or unqualified reference</p>
  </blockquote>
  
  <p>Highlighting the line of code: <code>After:=.Cells(1, 1)</code></p>
  
  <p>What must I do to group all rows (sans the header) with VBA?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Per comments, I edited my syntax to the below, which removes the error but this does not group all rows (excluding header).  How should this be updated to group by the used range?</p>
  
  <pre><code>  Sub GroupItTogether()
    Dim rLastCell As Range
    Set rLastCell = ActiveSheet.Cells.Find(What:="*", After:=Cells(1, 1), _    
      LookIn:=xlFormulas, LookAt:= _
      xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
    Range("A2" &amp; rLastCell).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1
  End Sub
  </code></pre>