title: Run time error 1004 when trying to sort data on three different values
body: <p>I've read at least fifteen different articles on this and tried a number of different possible solutions. I am trying to use the VBA code below to sort a worksheet of variable size by three different levels.</p>
  
  <p>When I step through the code I get an error 1004 at the .apply argument of the sort.</p>
  
  <p><strong>Run-time error '1004':</strong></p>
  
  <p><strong>The sort reference is not vald. Make sure that it's within the data you
  want to sort, and the first Sort By box isn't the same or blank.</strong></p>
  
  <p>Can anyone suggest a reason why or a solution to this problem?</p>
  
  <pre><code>Sub Subbing()
  
  Dim LastCell as String
  
  Range("A2").End(xlDown).Select
  
  LastCell = Selection.Offset(0, 13).Address
  Worksheets("Sheet1").Activate
  
  With ActiveWorkbook.Worksheets("Sheet1").Sort
          .SortFields.Clear
          .SetRange Range("A2", LastCell)
          .SortFields.Add Key:=ActiveWorkbook.Worksheets("Sheet1").Range("R2"), _ SortOn:=xlSortOnValues, Order:=xlAscending
          .SortFields.Add Key:=ActiveWorkbook.Worksheets("Sheet1").Range("S2"), _ SortOn:=xlSortOnValues, Order:=xlAscending
          .SortFields.Add Key:=ActiveWorkbook.Worksheets("Sheet1").Range("D2"), _ SortOn:=xlSortOnValues, Order:=xlAscending
          .Header = xlGuess
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
  
  End With
  End Sub
  </code></pre>
  
  <p>I look forward to your responses. I know this is a common question but I have tried all of the widely suggested methods of resolving my issue and to no avail.</p>
  
  <p>Kind Regards</p>
  
  <p>Pete</p>