title: Sort reference is not valid?
body: <p>I am trying to sort some columns horizontally, and keep running into this error. The code seems pretty simple, I'm not sure what I'm missing</p>
  
  <p>I need to move all of the data underneath each column header along with the header, and the amount of headers is subject to change so that's why I used the .End function to select my ranges.</p>
  
  <pre><code>Sub Macro4()
  '
  ' Macro4 Macro
  '
      Dim vcHeaders As Range
      Dim vcColumns As Range
  
  
  Worksheets("Copy").Range("D1").Select
  Set vcHeaders = Range(Selection, Selection.End(xlToRight))
  
  Worksheets("Copy").Range("D:D").Select
  Set vcColumns = Range(Selection, Selection.End(xlToRight))
  
  With ActiveWorkbook.Worksheets("Copy").Sort
      .SortFields.Add Key:=vcHeaders
      .SetRange vcColumns
      .Header = xlNo
      .Orientation = xlLeftToRight
      .Apply
  End With
  End Sub
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>"Run- time error '1004': The sort reference is not valid. Make sure
    that it's within the data you want to sort, and the first Sort By box
    isn't the same or blank."</p>
  </blockquote>
  
  <p>EDIT:
  I tried specifying vcHeaders and vcColumns as ranges in the Sort function, like the comments suggested, but I got the same error. Those variables are already ranges, and the second one (range) includes the first one (key). I am sorting left to right, so the key is a row, not a columns. I tried specifying it as a row too, and that didn't work. Any other ideas?</p>