title: Error using lbound/ubound depending on number of rows returned
body: <p>I have a bit of code that I have been using for a while to extract data from an Oracle database to Excel, but I am now getting an error with it if only 1 row is returned.  The SQL being used is fine, but I get the error "Error 9: subscript out of range" whenever a single row is returned.  Any help would be greatly appreciated.</p>
  
  <pre><code>Sub TFD()
  
  Dim cn As ADODB.Connection
  Dim rs As ADODB.Recordset
  Dim col As Integer
  Dim row As Integer
  Dim Query As String
  Dim mtxData As Variant
  
  ' Clear the current list on Sheet7
  Sheet7.Range("A2:C1000").ClearContents
  
  Set cn = New ADODB.Connection
  Set rs = New ADODB.Recordset
  
  ' Connection string to connect to database
  cn.Open ("Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=XXX)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=XXXXXXXX.XXX.XXXXXX.XXX)(PORT=1521)))(CONNECT_DATA=(SID=XXX)(SERVER=DEDICATED)));User Id=XXXXXXXX;Password=XXXXXXXX")
  
  ' Request list of project and database names from database
  rs.Open Sheet6.Range("TFD_SQL").Value, cn
      If rs.EOF Then
          Exit Sub
      Else
          With Sheet7
              col = 0
              'First Row: names of columns
              Do While col &lt; rs.Fields.Count
                  .Cells(1, col + 1) = rs.Fields(col).Name
                  col = col + 1
              Loop
              mtxData = Application.Transpose(rs.GetRows)
              .Range("A2").Resize(UBound(mtxData, 1) - LBound(mtxData, 1) + 1, UBound(mtxData, 2) - LBound(mtxData, 2) + 1) = mtxData
          End With
      End If
  
  ' Close the record set
  rs.Close
  
  ' Close the database connection
  cn.Close
  
  Exit Sub
  </code></pre>