title: How to pass range variables between subroutines in Excel VBA
body: <p>I'm trying to pass a range to a subroutine, but its throwing up a "Method 'Range' of object '_Global' failed" error.</p>
  
  <p>In the main I declare and define the range variable I want to use:</p>
  
  <pre><code>Sub maintest()
  
  Dim ScheduledSort As Range
  Set ScheduledSort = Range("F4:F321")
  
  Call test(ScheduledSort)
  End Sub
  </code></pre>
  
  <p>Then in the subroutine test I want it to sort using the range I passed it from the routine above:</p>
  
  <pre><code>Sub test(RangeForSort)
  
  Sheets("SheetTest").Select
  
  ' Sort in descending order
  ActiveWorkbook.Worksheets("SheetTest").AutoFilter.Sort.SortFields.Add _
      Key:=Range("RangeForSort"), SortOn:=xlSortOnValues, Order:=xlDescending, _
      DataOption:=xlSortTextAsNumbers
  With ActiveWorkbook.Worksheets("SheetTest").AutoFilter.Sort
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  End Sub
  </code></pre>
  
  <p>I think its going wrong at the <code>Key:=Range("RangeForSort")</code> but I can't work out why and how to fix it.<br>
  What is it I'm doing wrong with the Range and how do I fix it such that I can pass it any Range to sort on?<br>
  And if you have a better suggestion for what I'm trying to do, feel free to add!  :-)</p>