title: Name and then sort a dynamic range
body: <p>I have a range that length keeps changing.  I need to redefine the named range each time it changes and then sort it.</p>
  
  <p>I have this so far:</p>
  
  <pre><code>Sub Macro2()
  '
  ' Name and Sort
  '
      Range("A3").Select
      Range(Selection, Selection.End(xlDown)).Select
      Range(Selection, Selection.End(xlToRight)).Select
      ActiveWorkbook.Names.Add Name:="data4", RefersToR1C1:= _
          "='Data Storage'!R3C1:R25C18"
      ActiveWorkbook.Names("data4").Comment = ""
      Application.Goto Reference:="data4"
      ActiveWorkbook.Worksheets("Data Storage").sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Data Storage").sort.SortFields.Add Key:=Range( _
          "D3:D25"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
          xlSortNormal
      With ActiveWorkbook.Worksheets("Data Storage").sort
          .SetRange Range("A3:R25")
          .Header = xlGuess
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
  End Sub
  </code></pre>
  
  <p>But the next time the range changes it only sorts on the previous range.  I think it has to do with the R3C1:R25C18 reference but I don't know how to change that each time the range changes.</p>
  
  <p>Thanks for any help.</p>