title: How to sort filtered data in vba?
body: <p>I have a worksheet populated with data.  I need to filter the data that could  only show the info <code>w/in 5 miles</code>.  Once the data is filtered to <code>w/in 5 miles</code>, I need to sort the variance column in ascending order.  I used a record macro and attempted to incorporate it.  The filtering works fine but I get an error saying: </p>
  
  <blockquote>
    <p>Compile Error: Expected Array</p>
  </blockquote>
  
  <p>when I run it.  Here is a snippet of my code.  When the error pops up, the <code>Range</code> is highlighted on the 6th line of code.</p>
  
  <pre><code>.Worksheets("Market Work").Cells.Select
  Selection.AutoFilter
  .Worksheets("Market Work").Range("$A$1:$Q$" &amp; RowLast2).AutoFilter Field:=5, Criteria1:= _
      "w/in 5 miles"
  
  
  ActiveWorkbook.Worksheets("Market Work").Sort.SortFields.Clear
  ActiveWorkbook.Worksheets("Market Work").Sort.SortFields.Add Key:=Range( _
      "G2:G112"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
      xlSortNormal
  With ActiveWorkbook.Worksheets("Market Work").Sort
      .SetRange Range("A1:Q112")
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  </code></pre>