title: Select Dynamic Table Range In Excel Using VBA
body: <p>I am trying to select a dynamic table - I can figure out the copy/pasting part of the script, but I can't figure out how to initially select this table.</p>
  
  <p>The table is dynamic in terms of both number of rows and number of columns. This is so because this lone workbook will need to be usable by different business units, calling different SQL server tables. So the user puts their inputs in Sheet1, refreshes the connection, and a table is returned in Sheet2.</p>
  
  <p>Here are snippets, including a working and a broken portion:</p>
  
  <pre><code>    'Variable designations
      Dim rowcount As String
      Dim columncount As String
      Dim sheetref1 As String
      Dim sheetref2 As String
      Dim rangeselect1 As String
      Dim rangeselect2 As String
  
      rowcount = Cells(Rows.Count, 1).End(xlUp).Row
      columncount = Cells(1, Columns.Count).End(xlToLeft).Column
      sheetref1 = "Sheet1"
      sheetref2 = "Sheet2"
      rangeselect1 = "A2:A" &amp; rowcount
      rangeselect2 = "A1:" &amp; columncount &amp; rowcount '&lt;--BROKEN
  
      'Copy column with populated rows
      Sheets(sheetref1).Range(rangeselect1).Copy '&lt;--WORKING
  
      'Copy table with populated rows and columns
      Sheets(sheetref2).Range(rangeselect2).Copy '&lt;--BROKEN
  </code></pre>
  
  <p>So here <code>rangeselect2 = "A1:" &amp; columncount &amp; rowcount</code> I am trying to return something like A1:Z10 or A1:F3000 - the dynamic range (by the way, A1 is static). My attempt is for columncount to return "Z" or "F" or whatever the last column letter is, while rowcount (hopefully) properly returns the last row number.</p>
  
  <p>Hopefully this makes sense. I will gladly answer any further questions, and I greatly appreciate any advice/help.</p>