title: excel Vba error 400 when I added sorting to the end of my macro
body: <p>I Have a relatively long sub that adds data to another sheet in a bunch of columns based on where its coming from. this part of the code works perfectly, however I wanted to sort all the rows in the table up to the last row that was added. the sorting code that I added on to the end works if I hard code what cells to include in the range, but my range will grow each time the sub is run so I tried to make the range include the variable I named for the next empty row (1MaxRows). </p>
  
  <p>When I do this I get an error that says "400", in the past when I have gotten this error it is because i referenced the sheet or workbook wrong, but this time I didn't change any sheet references. The section of my code that gives me this error is as follows:</p>
  
  <pre><code>Columns("A:Q").Select
  ActiveWorkbook.Worksheets("Raw Data").Sort.SortFields.Clear
  ActiveWorkbook.Worksheets("Raw Data").Sort.SortFields.Add Key:=range("A2:A &amp; lMaxRows" _
      ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  ActiveWorkbook.Worksheets("Raw Data").Sort.SortFields.Add Key:=range("B2:B &amp; lMaxRows" _
      ), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("Raw Data").Sort
      .SetRange range("A1:Q &amp; lMaxRows")
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  </code></pre>
  
  <p>I have tried changing the range codes in a handful of ways but I always either get an overflow error or a 400 error. 
  Thank you for the help.</p>