title: how to display the rows and columns values in VBA for select query
body: <p>My actual code is the following:</p>
  
  <pre><code>Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
                  Call extract
              End Sub
              Private Sub Worksheet_SelectionChange(ByVal Target As Range)
              End SubSub extract()
              Dim cn As Object
                      Dim uid1, pass1, srvrnm --pass parm
              Set cn = CreateObject("ADODB.Connection")
              Dim rs As Object
              Set rs = CreateObject("ADODB.Recordset")
              Dim cmdSQLData As Object
              Set cmdSQLData = CreateObject("ADODB.Command")
              uid1 = "SSSS"   --user-id
              pass1 = "JJJJ"  --pass words
              srvrnm = "JJJJSDS" --server name
              On Error GoTo err1
              cn.Open "Driver=Teradata; DBCName="&amp; srvrnm&amp; ";uid="&amp; uid1&amp; ";AUTHENTICATION=ldap;pwd="&amp; pass1&amp; "; Trusted_Connection=True"
              Set cmdSQLData.ActiveConnection = cn
              On Error Resume Next
              query1 = "select tablename,databasename as xx from DBC.TABLES sample 2;"
              cmdSQLData.CommandText = query1
              cmdSQLData.CommandTimeout = 0
               Set rs = cmdSQLData.Execute()
              Sheet1.Cells(2, 1) = rs.Fields(0).Value
              Set rs = Nothing
              err1:
              End Sub
  </code></pre>
  
  <p>My question is how to get database table result in excel rows and column with as many rows as in table and consequent number of columns</p>