title: How do you select the entire excel sheet with Range using VBA?
body: <p>I found a similar solution to this question in c# <a href="https://stackoverflow.com/questions/4850738/how-to-select-the-whole-excel-sheet-in-excel-range-object-of-c">How to Select all the cells in a worksheet in Excel.Range object of c#?</a></p>
  
  <p>What is the process to do this in VBA?</p>
  
  <p>I select data normally by using "ctrl+shift over arrow, down arrow" to select an entire range of cells. When I run this in a macro it codes out A1:Q398247930, for example. I need it to just be</p>
  
  <pre><code>.SetRange Range("A1:whenever I run out of rows and columns")
  </code></pre>
  
  <p>I could easily do it myself without a macro, but I'm trying to make the entire process a macro, and this is just a piece of it. </p>
  
  <pre><code>Sub sort()
      'sort Macro
      Range("B2").Select
      ActiveWorkbook.Worksheets("Master").sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Master").sort.SortFields.Add Key:=Range("B2"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
      With ActiveWorkbook.Worksheets("Master").sort
          .SetRange Range("A1:whenever I run out of rows and columns")
          .Header = xlNo
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
  End Sub
  </code></pre>
  
  <p><strong>edit:</strong><br>
  There are other parts where I might want to use the same code but the range is say "C3:End of rows &amp; columns". Is there a way in VBA to get the location of the last cell in the document?</p>